arm auto-merge as fallback when M is blocked by repo rules#26
Merged
Conversation
When mergeStateStatus is CLEAN, decideMergeAction picks direct merge —
but CLEAN doesn't reflect ruleset requirements (e.g. unresolved threads,
required deployments), so the merge can fail with a generic 422. Instead
of just toasting the failure, fall through to enablePullRequestAutoMerge
so the PR lands as soon as GitHub is satisfied.
The fallback always attempts toggleAutoMerge — the server's
AutoMergeNotAllowedError is the source of truth, and the cached
autoMergeAllowed flag (now 2-min TTL'd, was infinite) can lag behind a
recent repo-settings change.
Also forwards GitHub's full multi-line error message instead of dropping
everything after the first newline, so toasts carry the actionable
detail ("A conversation must be resolved…") not just the header.
There was a problem hiding this comment.
Pull request overview
This PR improves the “press M to merge” workflow by handling cases where GitHub repo rulesets block a direct merge even when mergeStateStatus reports CLEAN, falling back to arming auto-merge and improving surfaced error messages. It also adds a TTL to the server-side repo-settings cache so toggling “Allow auto-merge” in GitHub takes effect shortly after.
Changes:
- Web: on direct merge failure, attempt to enable auto-merge as a fallback and show a more actionable toast.
- Server: forward GitHub’s full multi-line merge rejection message by joining non-empty lines with
—. - Server: add a 2-minute TTL to cached
getRepoSettingsresults (and update integration test cache mock accordingly).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/web/src/mutations.ts | Adds auto-merge fallback behavior when direct merge fails and updates UI cache/toasts accordingly. |
| packages/web/src/mutations.test.ts | Adds unit tests covering merge success, fallback success, and fallback failure paths. |
| packages/server/src/routes.ts | Improves merge rejection message formatting by joining non-empty lines. |
| packages/server/src/routes.test.ts | Updates tests to assert the new merged error-message format. |
| packages/server/src/fetchers.ts | Adds a 2-minute TTL when reading cached repo settings. |
| packages/server/src/fetchers.integration.test.ts | Extends cache mock to support TTL behavior via cacheAge. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+112
to
+117
| await api.toggleAutoMerge(target.instanceId, target.repo, target.number); | ||
| qc.setQueriesData<PR[]>({ queryKey: ["prs"] }, (old) => | ||
| old?.map((pr) => | ||
| matches(target)(pr) ? { ...pr, autoMerge: true } : pr, | ||
| ), | ||
| ); |
Comment on lines
+113
to
+117
| qc.setQueriesData<PR[]>({ queryKey: ["prs"] }, (old) => | ||
| old?.map((pr) => | ||
| matches(target)(pr) ? { ...pr, autoMerge: true } : pr, | ||
| ), | ||
| ); |
Comment on lines
+26
to
37
| const cacheTimes = new Map<string, number>(); | ||
| vi.mock("./cache.js", () => ({ | ||
| getCached: (key: string) => cacheStore.get(key) ?? null, | ||
| setCached: (key: string, data: unknown) => { | ||
| cacheStore.set(key, data); | ||
| cacheTimes.set(key, Date.now()); | ||
| }, | ||
| cacheAge: (key: string) => { | ||
| const t = cacheTimes.get(key); | ||
| return t == null ? null : Date.now() - t; | ||
| }, | ||
| })); |
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
Pressing M on a PR with
mergeStateStatus: CLEANpreviously triggered a direct merge, which surfaced an unhelpful 422 ("Repository rule violations found") when GitHub rulesets imposed requirements GraphQL doesn't reflect (e.g. unresolved review threads, required deployments).enablePullRequestAutoMergewhenever the direct merge fails — the PR lands once GitHub is satisfied. CachedautoMergeAllowedis no longer gating the fallback; the server'sAutoMergeNotAllowedErroris the source of truth.getRepoSettings) so togglingAllow auto-mergein the GitHub UI takes effect within minutes instead of being stuck on the first cached value.—) so the toast carries the actionable line, not just the header.Test plan
pnpm typecheck/pnpm lint/pnpm fmt:checkpnpm test— addedmutations.test.tscovering merge success, fallback success, and fallback-failure (AutoMergeNotAllowedError) pathsCLEANbut blocked by an open thread — confirm toast shows "Auto-merge enabled — direct merge blocked: …" and the PR is armedAllow auto-mergeon a repo, wait <2min, press M on aCLEANPR there — confirm direct-merge error is surfaced (no fallback)