Clarify auto-merge UI and errors when direct merge is available (#6777)

GitHub rejects enabling auto-merge on a PR that is already mergeable
with a "Pull request is in clean status" error.

* Suppress "Enable auto-merge" option in the UI when direct merge
  is available, while retaining "Disable auto-merge".
* Translate the GitHub "clean status" GraphQL error into an actionable
  message recommending direct merge.
This commit is contained in:
Jinjing
2026-06-29 14:40:53 -07:00
committed by GitHub
parent 584cec78c3
commit a978222184
4 changed files with 59 additions and 3 deletions
+18
View File
@@ -3379,6 +3379,24 @@ describe('GitHub GraphQL rate-limit guard', () => {
).toBe(false)
})
it('translates the GitHub clean-status rejection into an actionable message', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({
stdout: JSON.stringify({ id: 'PR_kwDO123', headRefOid: 'head-oid' })
})
.mockRejectedValueOnce(new Error('GraphQL: Pull request is in clean status'))
await expect(
setPRAutoMerge('/repo-root', 7, true, 'squash', undefined, {
owner: 'stablyai',
repo: 'orca'
})
).resolves.toEqual({
ok: false,
error: 'This pull request can already be merged. Use Merge instead of auto-merge.'
})
})
it('uses the queue-aware gh merge path when the base branch has a merge queue', async () => {
ghExecFileAsyncMock
.mockResolvedValueOnce({
+11 -1
View File
@@ -4077,12 +4077,22 @@ export async function setPRAutoMerge(
} catch (err) {
const message =
err instanceof Error ? err.message : typeof err === 'string' ? err : 'Unknown error'
return { ok: false, error: classifyGhError(message).message }
return { ok: false, error: classifySetAutoMergeError(message) }
} finally {
release()
}
}
// Why: GitHub rejects enabling auto-merge on a PR that can already merge with
// "Pull request is in clean status". Surface the actionable next step (merge
// directly) instead of the raw GraphQL error.
function classifySetAutoMergeError(message: string): string {
if (/in clean status/i.test(message)) {
return 'This pull request can already be merged. Use Merge instead of auto-merge.'
}
return classifyGhError(message).message
}
type PRAutoMergeIdentity = {
id?: string
headRefOid?: string