-
Notifications
You must be signed in to change notification settings - Fork 256
Enhance automatic pr preparation #7125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
6a147b7
5dff7f3
bf49277
87289e8
e83d365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,20 +18,41 @@ | |||||||||||||||||||||||||||||||||
| # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||||||||||||||||||||||||||||||||||
| # SOFTWARE. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| name: Convert PRs to Draft on Opening | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||
| contents: write | ||||||||||||||||||||||||||||||||||
| name: Pull Request preparation | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||
| types: [opened] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||
| convert_to_draft: | ||||||||||||||||||||||||||||||||||
| prepare_pr: | ||||||||||||||||||||||||||||||||||
| name: Prepare pull request | ||||||||||||||||||||||||||||||||||
| if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} | ||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||
| - run: gh pr ready --undo ${{ github.event.pull_request.number }} | ||||||||||||||||||||||||||||||||||
| - name: Checkout PR branch | ||||||||||||||||||||||||||||||||||
| uses: actions/checkout@v6 | ||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||
| ref: ${{ github.event.pull_request.head.ref }} | ||||||||||||||||||||||||||||||||||
| ssh-key: ${{ secrets.SSH_FAFOREVER_MACHINE_USER }} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Add snippet | ||||||||||||||||||||||||||||||||||
| working-directory: changelog/snippets | ||||||||||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||||||||||
| # Configure git | ||||||||||||||||||||||||||||||||||
| git config user.email "github@faforever.com" | ||||||||||||||||||||||||||||||||||
| git config user.name "FAForever Machine User" | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+46
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't overwrite an author-provided snippet. This always recreates 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| - name: Convert PR to draft | ||||||||||||||||||||||||||||||||||
| run: gh pr ready --undo ${{ github.event.pull_request.number }} | ||||||||||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||||||||||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||||||||||||||||||||||||||||||
| GH_REPO: ${{ github.repository }} | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Your explanation here... [Don't forget to change the category in the filename] (#XYZW). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: 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:
gh pr editdoes not work with onlypull-requests: writepermissions cli/cli#6274gh pr listdepends on the read permission for Issues cli/cli#5986Add explicit permissions for the draft conversion step.
This workflow relies on repo-default
GITHUB_TOKENpermissions, butgh pr ready --undorequirespull-requests: writepermission. 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