server: fall back to direct merge when auto-merge hits "clean status"#58
Open
AntonNiklasson wants to merge 1 commit into
Open
server: fall back to direct merge when auto-merge hits "clean status"#58AntonNiklasson wants to merge 1 commit into
AntonNiklasson wants to merge 1 commit into
Conversation
If a PR is already mergeable, GitHub's enablePullRequestAutoMerge mutation
returns UNPROCESSABLE ("Pull request Pull request is in clean status"),
because there's nothing for auto-merge to wait on. Match the error and
fall through to a direct squash merge so the click does the right thing.
There was a problem hiding this comment.
Pull request overview
This PR updates the server’s POST /:instanceId/prs/:owner/:repo/:prNumber/auto-merge route to handle GitHub’s “Pull request is in clean status” GraphQL error by falling back to a direct squash merge, avoiding a 500 when a PR is already mergeable.
Changes:
- Catch the “clean status” auto-merge enable error and perform a direct squash merge instead.
- Surface merge rejection errors from the fallback merge as
merge_rejected(422) with a flattened, user-actionable message. - Optimistically remove merged PRs from cached
prs/reviews, record the mutation, and schedule a resync (includingrecent-prs).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }); | ||
| scheduleResync(instanceId, ["prs", "reviews", "recent-prs"]); | ||
|
|
||
| return c.json({ ok: true, merged: true }); |
Comment on lines
+293
to
+300
| const fullRepo = `${owner}/${repo}`; | ||
| try { | ||
| await client.pulls.merge({ | ||
| owner, | ||
| repo, | ||
| pull_number: num, | ||
| merge_method: "squash", | ||
| }); |
Comment on lines
+290
to
+294
| // PR is already mergeable — GitHub refuses to queue auto-merge. | ||
| // Fall through to a direct squash merge to match user intent. | ||
| if (/clean status/i.test(msg)) { | ||
| const fullRepo = `${owner}/${repo}`; | ||
| try { |
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.
Summary
When toggling auto-merge on a PR that's already in a mergeable state, GitHub's
enablePullRequestAutoMergemutation refuses to enqueue because there's nothing to wait on. Today that surfaces as a 500 in the dashboard. This change catches that specific error and falls through to a direct squash merge, matching the user's intent ("merge this").Error response from server logs
Captured while clicking auto-merge on a PR that had already gone green:
The existing handler only caught
/auto.?merge is not allowed/i, so thisclean statusvariant bubbled up unhandled.Behavior
{ ok: true, merged: true }.merge_rejectederrors from the fallback merge are surfaced the same way the dedicated/mergeendpoint does.Test plan