Skip to content

Enable automerge and automatic branch cleanup for automated PRs (#56) - #57

Merged
Stensel8 merged 1 commit into
mainfrom
development
Mar 29, 2026
Merged

Enable automerge and automatic branch cleanup for automated PRs (#56)#57
Stensel8 merged 1 commit into
mainfrom
development

Conversation

@Stensel8

Copy link
Copy Markdown
Member

No description provided.

* 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>
@Stensel8 Stensel8 self-assigned this Mar 29, 2026
@Stensel8 Stensel8 added the enhancement New feature or request label Mar 29, 2026
Copilot AI review requested due to automatic review settings March 29, 2026 12:54
@Stensel8
Stensel8 merged commit e81263f into main Mar 29, 2026
3 checks passed
@Stensel8
Stensel8 deleted the development branch March 29, 2026 12:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md
Comment on lines +100 to +103
**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

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread .github/AUTOMERGE.md
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`:

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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`:

Copilot uses AI. Check for mistakes.
type: string

permissions:
contents: write

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
contents: write
contents: write
issues: write

Copilot uses AI. Check for mistakes.

permissions:
contents: write
pull-requests: write

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pull-requests: write
pull-requests: write
issues: write

Copilot uses AI. Check for mistakes.

permissions:
contents: write
pull-requests: write

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
pull-requests: write
pull-requests: write
checks: read

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines 94 to +99
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:

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread .github/AUTOMERGE.md
Comment on lines +110 to +115
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`.

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Comment thread .github/AUTOMERGE.md
Comment on lines +221 to +222
- [Auto-Update Dependencies Workflow](../workflows/auto-update-dependencies.yml)
- [Check Dependencies Workflow](../workflows/check-dependencies.yml)

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
- [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)

Copilot uses AI. Check for mistakes.
Comment on lines +76 to +79
review.user.login === 'Stensel8'
);

console.log(`Has approval from Stensel8: ${hasApproval}`);

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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}`);

Copilot uses AI. Check for mistakes.
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.'

Copilot AI Mar 29, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.'

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants