disable automerge when adding existing PRs to stack#120
Conversation
When a user runs `gh stack submit` and an existing PR is discovered for
a branch via `FindPRForBranch`, that PR may have auto-merge enabled.
Auto-merge is incompatible with stacked PRs because the PR would merge
on its own, breaking the stack's base chain.
Previously, the eligibility guard for auto-merge was only in the `link`
command (which blocks such PRs with an error). The `submit` command had
no such check, allowing users to add auto-merge-enabled PRs to a stack
by running `init` followed by `submit`.
This change adds auto-merge detection and automatic disabling in
`submit`'s `ensurePR` function. When an existing PR with auto-merge
enabled is discovered, the CLI disables auto-merge via the
`disablePullRequestAutoMerge` GraphQL mutation and warns the user.
If the disable call fails, submit continues with a warning (non-fatal).
The `link` command retains its stricter behavior of blocking auto-merge
PRs outright, since the user explicitly chose those PRs and can fix
them before retrying.
Changes:
internal/github/github.go:
- Add DisableAutoMerge() method using the
disablePullRequestAutoMerge GraphQL mutation
internal/github/client_interface.go:
- Add DisableAutoMerge(prID string) error to ClientOps interface
internal/github/mock_client.go:
- Add DisableAutoMergeFn field and mock implementation
cmd/submit.go:
- In ensurePR, after discovering an existing PR with auto-merge
enabled, call DisableAutoMerge before proceeding. Warns on
success ("Disabled auto-merge for PR #N (incompatible with
stacked PRs)") and on failure ("failed to disable auto-merge").
cmd/submit_test.go:
- Add TestSubmit_DisablesAutoMergeOnExistingPR: verifies auto-merge
is disabled and warning is shown
- Add TestSubmit_DisableAutoMergeFailure_ContinuesWithWarning:
verifies submit continues even if the disable call fails
- Add TestSubmit_NoAutoMerge_SkipsDisable: verifies DisableAutoMerge
is not called for PRs without auto-merge
There was a problem hiding this comment.
Pull request overview
This PR closes a loophole where users could bypass the link command's auto-merge guard by running init on a branch with an auto-merge-enabled PR and then submit to adopt it into a stack. The fix adds auto-merge detection and automatic disabling during submit's PR reconciliation phase.
Changes:
- Adds a
DisableAutoMergeGraphQL mutation method following the same pattern asMarkPRReadyForReview - Integrates auto-merge detection in
ensurePRas a non-fatal check that warns the user when auto-merge is disabled - Includes three test cases covering success, failure (continues with warning), and no-op scenarios
Show a summary per file
| File | Description |
|---|---|
internal/github/github.go |
New DisableAutoMerge() method using disablePullRequestAutoMerge GraphQL mutation |
internal/github/client_interface.go |
Adds DisableAutoMerge to the ClientOps interface |
internal/github/mock_client.go |
Adds DisableAutoMergeFn field and mock implementation |
cmd/submit.go |
Detects and disables auto-merge on existing PRs in ensurePR |
cmd/submit_test.go |
Three new tests covering all auto-merge disable scenarios |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 5/5 changed files
- Comments generated: 0
ktravers
left a comment
There was a problem hiding this comment.
Do we want to force the user to disable auto merge themselves? Do we foresee anyone getting grumpy about us disabling it for them without asking for confirmation first?
And actually, how tricky would it be to get user confirmation before disabling? That could be a nice prompt to add.
This isn't a bad idea. It would be nice to confirm you are ok with it disabling before it disables auto merge. Like an eject button before we disable auto merge and add the PR to the stack. |
Disable auto-merge on existing PRs during
submitWhen
gh stack submitdiscovers an existing PR for a branch, that PR may have auto-merge enabled. Auto-merge is incompatible with stacked PRs because the PR would merge independently, breaking the stack's base chain.Previously, users could work around the
linkcommand's auto-merge guard by runninginiton a branch with an auto-merge-enabled PR, thensubmitto add it to a stack. Thesubmitcommand had no auto-merge check, so the PR was adopted without any validation.This change adds auto-merge detection to
submit'sensurePRfunction. When an existing PR with auto-merge enabled is found, theCLI automatically disables auto-merge via the
disablePullRequestAutoMergeGraphQL mutation and warns the user. If the disable call fails, submit continues with a warning (non-fatal).Changes
internal/github/github.go: addDisableAutoMerge()method using thedisablePullRequestAutoMergeGraphQL mutationinternal/github/client_interface.go: addDisableAutoMergetoClientOpsinterfaceinternal/github/mock_client.go: addDisableAutoMergeFnfield and mock implementationcmd/submit.go: inensurePR, detect auto-merge-enabled PRs and disable auto-merge before adding to the stackcmd/submit_test.go: 3 new tests — auto-merge disabled successfully, disable failure continues with warning, and no-op when auto-merge is not enabledStack created with GitHub Stacks CLI • Give Feedback 💬