disable automerge when adding existing PRs to stack#120
Open
skarim wants to merge 1 commit into
Open
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
Contributor
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 💬