Repository navigation
fix(server): turning on auto-merge merges a pull request that is already ready - #495
Merged
Merged
Conversation
…ady ready GitHub reports viewerCanEnableAutoMerge as false once a pull request has nothing left to wait on. The server read that as missing access and refused with "You need write access", which a panel that went stale after the last check passed would hit. A viewer who may merge is now let through, and `gh pr merge --auto` merges such a pull request immediately. The merge is confirmed and published afterwards, as it is for a direct merge, so threads settle.
incognitojam
enabled auto-merge (squash)
September 26, 2026 14:54
incognitojam
pushed a commit
that referenced
this pull request
Sep 28, 2026
Fork adaptation: fork #194's stack ladder field on the pull request detail is renamed from stack to stackLadder, because upstream now uses stack for list-entry stack membership. Auto-merge authorization from fork #495 still applies to non-stack actions. (cherry picked from commit de37964) Upstream-PR: 10875
16 tasks
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.
If the pull request panel went stale after the last required check passed, it still offered Auto-merge, and pressing it failed with "Could not turn on auto-merge — You need write access on this repository", even for a maintainer.
The refusal came from the server's own permission check, not from GitHub. The server asks GitHub for
viewerCanEnableAutoMerge, which depends on the pull request's state as well as the viewer's access, and is false once nothing is left to wait on. The server treated that as missing access.Fix
gh pr merge --autoalready merges a pull request that GitHub reports as CLEAN, HAS_HOOKS or UNSTABLE immediately, with the requested strategy, and arms auto-merge otherwise (isImmediatelyMergeablein gh'spkg/cmd/pr/merge/merge.go). gh reads the pull request's current state, so the stale panel does not matter, and merge queues are still respected. GitLab and Azure DevOps already grant auto-merge together with merge, so only GitHub changes.The panel's buttons are unchanged: on a pull request that is ready it still offers Merge, and its success toast for auto-merge already says it merges "sooner if it already is".
Validation
PullRequestService.test.tsgives the fake host a viewer who may merge but not arm auto-merge, and a pull request that reads back as merged. It checks that auto-merge is sent with the requestedsquashstrategy and that the merge is published. Run against the service without this fix, it fails with the same "You need write access" refusal as in the bug. With the fix, all 111 tests in the file pass.Written by an agent (Claude Code, claude-opus-5-5).