Enhance automatic pr preparation#7125
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/pr-preparation.yaml:
- Around line 46-52: The workflow always overwrites category.${{
github.event.pull_request.number }}.md by copying template-snippet.md, which can
clobber an author-provided snippet; change the logic around FILE to first check
for file absence and only create/copy when the target does not exist, and when
committing only add that generated filename instead of git add . so you stage
and commit the new FILE (refer to the FILE variable and the cp/sed/git add/git
commit/git push commands) to avoid touching other files in the branch.
- Around line 23-25: Add explicit GITHUB_TOKEN permissions so the
draft-conversion step can run gh pr ready --undo; add a permissions block
granting pull-requests: write (either globally under the workflow root or on the
specific job that runs the draft conversion) and ensure GITHUB_TOKEN is used
there; update the workflow to include permissions: pull-requests: write so the
gh command can undo drafts successfully.
In `@changelog/snippets/category.7125.md`:
- Line 1: The changelog snippet file category.7125.md is still a template;
rename the file to the correct final category name (replace "category" with the
actual category slug for PR 7125) and edit the file contents to remove the
placeholder line "Your explanation here... [Don't forget to change the category
in the filename] (`#7125`)." and replace it with the finalized changelog entry
text for PR 7125 (brief summary, scope, and PR reference). Ensure the new
filename matches the repository's changelog category conventions and the file
body contains the final, publication-ready snippet.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7d577447-937c-408d-9650-9b894e921d3e
📒 Files selected for processing (3)
.github/workflows/pr-preparation.yamlchangelog/snippets/category.7125.mdchangelog/snippets/sections/template-snippet.md
| on: | ||
| pull_request: | ||
| types: [opened] |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n .github/workflows/pr-preparation.yamlRepository: FAForever/fa
Length of output: 2728
🌐 Web query:
gh cli gh pr ready permission requirements contents write vs pull-requests write
💡 Result:
To use the gh pr ready command in a GitHub Actions workflow, you generally need the pull-requests: write permission [1]. While pull-requests: write is the primary requirement for modifying the state of a pull request, the specific permissions required by the GitHub CLI (gh) can be nuanced depending on the repository context and the specific operations being performed [1][2]. Key considerations for permission requirements: 1. Pull-Requests Permission: The pull-requests: write permission is necessary to change the status of a pull request (e.g., marking it as ready or converting it back to a draft) [1][3]. 2. Contents Permission: The contents: write permission is typically required if your workflow involves pushing changes, tags, or other repository modifications [1]. It is not strictly required for the gh pr ready command itself, but it is often included in workflows that perform broader PR management tasks [1]. 3. Additional Scopes: Depending on the complexity of your workflow, you may encounter requirements for other permissions. For example: - repository-projects: read may be required if the CLI attempts to access project metadata associated with the pull request [1]. - issues: read is often necessary for commands like gh pr list, as the CLI may rely on issue-related search or metadata endpoints [2]. - If you are using features like assigning reviewers or teams, you might face limitations with the default GITHUB_TOKEN, which may require a Personal Access Token (PAT) with broader scopes (such as read:org) [4][3]. In summary, while pull-requests: write is the core requirement for gh pr ready, you should configure your workflow permissions based on the full set of gh commands being executed to avoid 403 Forbidden errors [1][5]. If you encounter unexpected failures, check if your workflow requires additional read access to repository projects or issues [1][2].
Citations:
- 1:
gh pr editdoes not work with onlypull-requests: writepermissions cli/cli#6274 - 2:
gh pr listdepends on the read permission for Issues cli/cli#5986 - 3: Can't use GitHub CLI with GITHUB_TOKEN to mark PR as ready from GitHub Action cli/cli#1314
- 4: What permissions are required to use 'gh pr create --assignee myOrg/myTeam' in a github action (GITHUB_TOKEN)? cli/cli#8214
- 5: Add missing GitHub permissions to workflows using GitHub API toolsets github/gh-aw#10020
Add explicit permissions for the draft conversion step.
This workflow relies on repo-default GITHUB_TOKEN permissions, but gh pr ready --undo requires pull-requests: write permission. On repos with read-only defaults, this step can fail even though earlier steps succeed.
Suggested fix
on:
pull_request:
types: [opened]
+
+permissions:
+ pull-requests: write🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/pr-preparation.yaml around lines 23 - 25, Add explicit
GITHUB_TOKEN permissions so the draft-conversion step can run gh pr ready
--undo; add a permissions block granting pull-requests: write (either globally
under the workflow root or on the specific job that runs the draft conversion)
and ensure GITHUB_TOKEN is used there; update the workflow to include
permissions: pull-requests: write so the gh command can undo drafts
successfully.
| FILE=category.${{ github.event.pull_request.number }}.md | ||
| cp sections/template-snippet.md $FILE | ||
| sed -i "s/XYZW/${{ github.event.pull_request.number }}/g" $FILE | ||
|
|
||
| git add . | ||
| git commit -m "Add snippet template" | ||
| git push |
There was a problem hiding this comment.
Don't overwrite an author-provided snippet.
This always recreates category.<pr>.md from the template. If the branch already has a real snippet, the workflow replaces it with placeholder text and pushes that regression back to the PR branch. Guard on file absence and only stage the generated file.
Suggested fix
- FILE=category.${{ github.event.pull_request.number }}.md
- cp sections/template-snippet.md $FILE
- sed -i "s/XYZW/${{ github.event.pull_request.number }}/g" $FILE
-
- git add .
- git commit -m "Add snippet template"
- git push
+ FILE="category.${{ github.event.pull_request.number }}.md"
+ if [ ! -f "$FILE" ]; then
+ cp sections/template-snippet.md "$FILE"
+ sed -i "s/XYZW/${{ github.event.pull_request.number }}/g" "$FILE"
+
+ git add "$FILE"
+ git commit -m "Add snippet template"
+ git push
+ fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| FILE=category.${{ github.event.pull_request.number }}.md | |
| cp sections/template-snippet.md $FILE | |
| sed -i "s/XYZW/${{ github.event.pull_request.number }}/g" $FILE | |
| git add . | |
| git commit -m "Add snippet template" | |
| git push | |
| FILE="category.${{ github.event.pull_request.number }}.md" | |
| if [ ! -f "$FILE" ]; then | |
| cp sections/template-snippet.md "$FILE" | |
| sed -i "s/XYZW/${{ github.event.pull_request.number }}/g" "$FILE" | |
| git add "$FILE" | |
| git commit -m "Add snippet template" | |
| git push | |
| fi |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/pr-preparation.yaml around lines 46 - 52, The workflow
always overwrites category.${{ github.event.pull_request.number }}.md by copying
template-snippet.md, which can clobber an author-provided snippet; change the
logic around FILE to first check for file absence and only create/copy when the
target does not exist, and when committing only add that generated filename
instead of git add . so you stage and commit the new FILE (refer to the FILE
variable and the cp/sed/git add/git commit/git push commands) to avoid touching
other files in the branch.
Description of the proposed changes
Testing done on the proposed changes
Additional context
Checklist
Summary by CodeRabbit