Enable automerge and automatic branch cleanup for automated PRs (#56) - #57
Conversation
* Initial plan * Add automerge and auto-delete branch workflows Agent-Logs-Url: https://github.com/Stensel8/Scripts/sessions/df6edc3b-7b62-4694-b1ab-8e1558816123 Co-authored-by: Stensel8 <102481635+Stensel8@users.noreply.github.com> * Add comprehensive automerge documentation Agent-Logs-Url: https://github.com/Stensel8/Scripts/sessions/df6edc3b-7b62-4694-b1ab-8e1558816123 Co-authored-by: Stensel8 <102481635+Stensel8@users.noreply.github.com> --------- Co-authored-by: anthropic-code-agent[bot] <242468646+Claude@users.noreply.github.com> Co-authored-by: Stensel8 <102481635+Stensel8@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds GitHub Actions automation to auto-approve/enable auto-merge for trusted automated PRs and to delete merged branches, with accompanying documentation updates.
Changes:
- Document automatic PR approval/merge and branch cleanup in the README.
- Add an automerge workflow that approves eligible PRs and enables GitHub auto-merge.
- Add a workflow + documentation for deleting merged branches and describing behavior/configuration.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| README.md | Documents the new automerge + branch cleanup automation. |
| .github/workflows/automerge.yml | New workflow to auto-approve and enable auto-merge for eligible PRs. |
| .github/workflows/auto-delete-branch.yml | New workflow to delete merged PR branches (and optionally comment). |
| .github/AUTOMERGE.md | New documentation for both workflows, triggers, and troubleshooting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| **Automerge Workflow:** | ||
| - Automatically approves PRs created by `Claude` or `github-actions[bot]` | ||
| - Enables automerge for PRs with branches starting with `automated-update/` or `claude/` | ||
| - Only merges when all required checks pass |
There was a problem hiding this comment.
README says automerge approves PRs created by Claude or github-actions[bot], but the workflow eligibility is broader (it also matches by branch prefix, regardless of author). Please align the README with the actual criteria (or tighten the workflow criteria if the README is the intended behavior).
| The workflow uses the following merge method: | ||
| - **Default**: `SQUASH` - Combines all commits into a single commit | ||
|
|
||
| To change the merge method, edit line 124 in `.github/workflows/automerge.yml`: |
There was a problem hiding this comment.
The doc references "edit line 124" to change merge method, but in the current automerge.yml the mergeMethod: 'SQUASH' setting is at a different line. Consider referencing the key name/section instead of a hard-coded line number (or update the line number to match).
| To change the merge method, edit line 124 in `.github/workflows/automerge.yml`: | |
| To change the merge method, update the `mergeMethod` setting in `.github/workflows/automerge.yml`: |
| type: string | ||
|
|
||
| permissions: | ||
| contents: write |
There was a problem hiding this comment.
This workflow posts a PR comment via github.rest.issues.createComment(...) but the job permissions only grants contents: write. Add issues: write (or switch to an API that aligns with the granted scopes) so the comment step doesn't fail due to insufficient token permissions.
| contents: write | |
| contents: write | |
| issues: write |
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write |
There was a problem hiding this comment.
The workflow uses github.rest.issues.createComment(...) in the automerge error path, but permissions doesn't include issues: write. With scoped GITHUB_TOKEN permissions this can fail to post the failure comment; consider adding issues: write if you want that behavior to be reliable.
| pull-requests: write | |
| pull-requests: write | |
| issues: write |
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write |
There was a problem hiding this comment.
permissions doesn't include checks: read, but the workflow calls github.rest.checks.listForRef(...) later. With fine-grained GITHUB_TOKEN permissions, this can 403 and break the job. Either add checks: read permission or remove the Checks API call and rely on GitHub auto-merge to wait for required checks.
| pull-requests: write | |
| pull-requests: write | |
| checks: read |
| This automated system provides **true self-maintenance** - the repository automatically detects updates, creates PRs with code changes, and only requires human review and testing before merging. | ||
|
|
||
| ### Automatic PR Approval and Merge | ||
|
|
||
| The repository includes workflows that automatically approve and merge Pull Requests from trusted automation: | ||
|
|
There was a problem hiding this comment.
The README now states the system "only requires human review and testing before merging", but also introduces auto-approval/automerge. Consider rewording to clarify that human review is required only for certain PR classes (e.g., drafts/NGINX) and that trusted automation PRs can be merged automatically.
| Dependabot PRs are also eligible for automerge if: | ||
| - They pass all status checks | ||
| - The workflow approves them automatically | ||
|
|
||
| To disable automerge for Dependabot PRs, you can modify the eligibility check in `automerge.yml`. | ||
|
|
There was a problem hiding this comment.
This section claims Dependabot PRs are eligible for automerge, but automerge.yml currently doesn't include dependabot[bot] or dependabot/ branches in its eligibility check. Either update the workflow to include Dependabot explicitly, or adjust the documentation to match current behavior.
| Dependabot PRs are also eligible for automerge if: | |
| - They pass all status checks | |
| - The workflow approves them automatically | |
| To disable automerge for Dependabot PRs, you can modify the eligibility check in `automerge.yml`. | |
| Dependabot PRs are **not** currently included in the automerge eligibility criteria and will **not** be auto-approved or auto-merged by default. | |
| To enable automerge for Dependabot PRs, update the eligibility check in `.github/workflows/automerge.yml` to treat Dependabot as a trusted automation source (for example, by allowing the `dependabot[bot]` author or `dependabot/` branch prefixes). | |
| If you prefer to keep Dependabot PRs manual-only, no changes to the workflow are required. |
| - [Auto-Update Dependencies Workflow](../workflows/auto-update-dependencies.yml) | ||
| - [Check Dependencies Workflow](../workflows/check-dependencies.yml) |
There was a problem hiding this comment.
These links are broken: from .github/AUTOMERGE.md, ../workflows/... resolves to <repo>/workflows/... (which doesn't exist). Use ./workflows/... or an absolute repo path like .github/workflows/... so the links point to the actual workflow files.
| - [Auto-Update Dependencies Workflow](../workflows/auto-update-dependencies.yml) | |
| - [Check Dependencies Workflow](../workflows/check-dependencies.yml) | |
| - [Auto-Update Dependencies Workflow](./workflows/auto-update-dependencies.yml) | |
| - [Check Dependencies Workflow](./workflows/check-dependencies.yml) |
| review.user.login === 'Stensel8' | ||
| ); | ||
|
|
||
| console.log(`Has approval from Stensel8: ${hasApproval}`); |
There was a problem hiding this comment.
hasApproval is checking for an approval from Stensel8, but the approval this workflow creates will be authored by the workflow token (typically github-actions[bot]). As written, hasApproval will remain false and the workflow can submit duplicate approvals on every trigger. Consider detecting any existing approval (or specifically one from github-actions[bot]) instead of a hard-coded username.
| review.user.login === 'Stensel8' | |
| ); | |
| console.log(`Has approval from Stensel8: ${hasApproval}`); | |
| (review.user.login === 'github-actions[bot]' || review.user.type === 'Bot') | |
| ); | |
| console.log(`Has approval from a bot (including github-actions[bot]): ${hasApproval}`); |
| repo: context.repo.repo, | ||
| pull_number: prNumber, | ||
| event: 'APPROVE', | ||
| body: '✅ Automatically approved by automerge workflow.\n\nThis PR was created by trusted automation and has passed all checks.' |
There was a problem hiding this comment.
The approval review body claims the PR "has passed all checks", but this step can run before checks complete (and even when checks are failing), since should_approve doesn't depend on check status. Please update the message to be accurate or gate approval on successful checks if that's the intent.
| body: '✅ Automatically approved by automerge workflow.\n\nThis PR was created by trusted automation and has passed all checks.' | |
| body: '✅ Automatically approved by automerge workflow.\n\nThis PR was created by trusted automation and will be merged automatically once all required checks pass.' |
No description provided.