Repository navigation
fix: check mergeability before the approval - #1720
Merged
Merged
Conversation
approve --merge approved a pull request and only then found GitHub reports it unstable (the automated review holds it), so the approval was left standing without the merge. The state is now read before anything is written: unless GitHub says clean, nothing is approved or merged, the state and why it blocks are named, and the way to approve without merging is given. An unknown or unrecognised state is not clean. The look after the approval stays for a state that changes in between. Tested: real CLI against the GitHub stand-in, pr-review-approve and admin-pr-reviews-cli suites.
y in next approves and squash-merges, but was offered for any state except dirty and behind, so a pull request the automated review holds (unstable) was approved and then refused the merge. y is now offered only when GitHub reports clean, settled by asking again while it is unknown; the card names the state, why it blocks and how to approve without merging, and answering y anyway writes nothing. --force does not reach the state. approveAllowed takes the state as a required argument and treats a missing one as not clean. Tested: real CLI against the GitHub stand-in, admin-pr-reviews-cli and pr-review-next suites.
A mutation pass showed that reading a failed or moved re-read of the mergeable state as clean, or ignoring it in approve, left every test green. The stand-in can now fail or move the head for the administrator's own reads only, and approve --merge and next each assert that nothing is written and the reason is said.
Records that a merge asked for is checked before anything is approved, settles the part of ADR 0092's open item it answers, and adds the Unreleased changelog entry. The clean-only rule is unchanged.
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1720Version: 🤖 Updated on each push. |
A review mutation pass left two mutants alive: skipping the precheck when --force is given, and reading an answer without mergeable_state as clean. The stand-in can now omit the field, and approve --merge, next and the settle reader each assert it reads as unknown with nothing written; --merge --force on a held pull request refuses.
mergeRefusal looked the reason up in an object literal, so a state word such as constructor yielded a function's source as the reason. The table is a Map; the state is still refused as one this tool does not merge on.
next folded a failed read and a moved head into the string unknown, so the card said GitHub had not said when a 502 or a push had happened. The answer is now one MergeCheck value (ok, why, a card phrase, and the advice) made by mergeCheckOf and checkMergeable, the only place that decides whether a merge may be asked for; approveAllowed takes it, so the card carries the real reason. settleMergeState takes the pull request as read (head and state in one value) instead of a head and a loose state. A state that will not clear by itself still advises approving without --merge; unknown and a failed read say to try again in a moment. The approve-only hint is named once instead of recomputed. Tested: pr-review-approve, pr-review-next and admin-pr-reviews-cli.
settleMergeState did not look at the pull request's own state on a re-read, so one closed or merged meanwhile was judged only by its mergeable_state. A re-read that finds it closed or merged is now its own result: the check before an approval refuses with nothing written and no advice to retry, and the look before the merge says it was not merged and the approval stands. Tested: pr-review-approve, admin-pr-reviews-cli.
The state was read before the confirmation prompt and, in next, before the card, and nothing looked again just before the approval is written, which cannot be taken back. Both approve --merge and y now call one helper, recheckBeforeApproval, that reads the state fresh (one request when clean) and refuses with nothing written, saying it is the second look. The early check stays for the user's sake; the look after the approval stays for the window that remains. Tested: a stand-in that changes the state, head, status or openness after the first read, for approve and next; pr-review-approve and admin-pr-reviews-cli.
The refusal sentence and the approve and next help said a held review is reported as unstable and that unstable means a check is failing. GitHub's unstable is a check or status that is not required and is not passing or has not reported, and a held review producing it is expected, not observed. The text now says that, and the help says expected. The help also says the state is checked again just before the approval is written. Tested: pr-review-approve, pr-review-next, admin-pr-reviews-cli.
Records the read right before the approval, the reasons a failed read now carries, the advice that differs by state, a pull request found no longer open, and the unstable wording as expected rather than observed. Corrects the amendment's list of remaining answers and its approve-alone sentence, and states why a protection that requires an approval is not a case today. Changelog entry matches.
With --force skipping the early check the late look still wrote nothing, so the mutant survived: the outcome was the same, only later. The --force and held tests now assert the refusal came from the early check, before the card and without the late look's prefix.
No change in wording; the line had grown past the rest of the paragraph.
ADR 0093 said the four legacy repositories' ruleset pins their BIDS check; they have no ruleset, only classic branch protection with the bids-validation and version-check contexts, so the bullet now says so and agrees with the amendment below it.
Moving the late look above the confirmation kept every test green and reopened the interactive window it exists to close. approve --merge without --yes makes one read only when the confirmation is not given, and next makes none beyond the card's when q is answered. Both fail when the look is taken early (scratch-copy mutants).
next told the administrator to try y again, which was untrue in two cases: when y is not offered typing it does not look again, and a card refused for a moved head is pinned to the head it was shown for, so y refuses every time. next now says s skips it and a fresh next run looks again. A moved head gets its own advice (rerun, in the type, not only the string) since waiting does not help it, and the late look's wording says the head changed since it was read, not while it was being read. Tested: pr-review-approve, pr-review-next, admin-pr-reviews-cli.
MergeSeen encoded a state that was not read as an absent optional; it is now null, so it is stated at every call site. MergeResult's loose mergeableState string is replaced by the MergeRefused every other caller already uses. Compile-checked; no behaviour change. Tested: pr-review-approve, pr-review-next, admin-pr-reviews-cli.
ADR 0093's main merge bullet listed only the read before and the look after; it now includes the read just before the approval is written and says plainly that GitHub has no approve-and-merge call, so the window is narrowed to one request, not closed. The same sentence is in the help and the changelog. The next advice (s skips, a fresh run looks again) and the advice for a moved head are described too.
CHANGELOG.md: kept dev's Unreleased entries (the weekly drift check, the nightly issue, the workflow gh-call test, the modality filter) and this branch's entry after them, in the one Fixed section. No other conflict.
3 of 4 tasks
neuromechanist
added a commit
that referenced
this pull request
Oct 13, 2026
2 tasks done
4 tasks done
This branch was previously deployed
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.
Refs #1707 (decision 3 of "Decisions for the maintainer"). Follows #1705, which recorded this as "Recorded, not changed".
Problem
nemar admin pr-reviews approve --mergeandyinnemar admin pr-reviews nextapproved a pull request and only then read GitHub'smergeable_state. A pull request the automated review holds has a check that is not required and not passing, which GitHub is expected to report asunstable, so the merge was refused after the approval had been written. The administrator was left with an approval they asked for only as the first half of a pair. ADR 0093 says a merge is attempted only when GitHub reportsclean; it did not say when that is read.Cause, from the code and confirmed by running the new tests against
devbefore the fix:approve --merge: nothing read the state beforesubmitApproval. The only check was insidemergeWhenClean, which runs after the approval.next:approveAllowedrefuseddirtyandbehindand let every other state through, soywas offered forunstable,blocked,unknown,has_hooksand a missing state.On
devthe stand-in run showedApproved nm000201 #7 ...followed byNot merged: ... The approval stands.andDone: 1 approved but not merged.What changed
ADR 0093's "clean only" rule is not changed. What moves is where it is checked.
approve --mergereads the state first (asking again for a few seconds while it isunknown) and, unless it isclean, writes nothing: no approval, no merge. It says which state GitHub reported or which read failed, why that blocks, and what to do: for a state that will not clear by itself, runapprovewithout--merge; forunknownor a failed read, run the same command again in a moment; for a head that changed since it was read, run it again to read the new one. Innextthe advice is thatsskips the card and a freshnextrun looks again (a card is pinned to the head it was shown for, andywhen it is not offered does not look again).--dry-run --mergegives the same answer. This happens before the confirmation question.recheckBeforeApproval) that bothapprove --mergeandycall, because the early check can be as old as the confirmation prompt or the time a card was on screen and an approval cannot be taken back. One extra GET when clean; a refusal says it came from that second look. It is taken after the confirmation (and innextwhenyis answered, not when the card is shown), which tests pin. GitHub has no approve-and-merge call, so this narrows the window to one request and does not close it; the look after the approval still catches a check that starts in between.yinnextis offered only when both required checks are green and the state isclean, settled the same way before the card is shown. The card names the state or the failed read and the approve-without-merging command; typingyanyway is refused with the reason and writes nothing.--forcedoes not reach it.clean:unstable,blocked,behind,dirty,draft,has_hooks, a state nobody has heard of, a missing state, a state stillunknownafter the re-asks, a re-read that fails, finds the branch moved, or finds the pull request closed or merged.MergeCheck(ok, the sentence, a card phrase, the advice), made bycheckMergeableandmergeCheckOf, is what every caller uses, so the card says what actually happened instead of "GitHub has not said".settleMergeStatetakes the pull request as read (head and state in one value; a state not yet read isnull, not an absent field), and a not-merged result carries the sameMergeRefusedinstead of a loose state string. A state named like an object property (constructor) no longer leaks into the sentence.approvewithout--mergeis unchanged (same verdict gate, same--force). When GitHub's state is one that will not clear by itself, its closing hint says so instead of suggesting--merge.unstableis described as a check or status that is not required and is not passing or has not reported, and a held review producing it is called expected, not observed.Unreleasedentry.Cost of the second look: one more request to the GitHub REST API per
approve --mergeorywhen the state is clean (three reads of the pull request in all instead of two: the first read, the look before the approval, the look before the merge). An approval alone costs nothing extra.Test evidence
Tests were written first and run on
devcode: 6 of the newapprovetests failed there, and 7 of the new or changednextandapproveAllowedtests. The review round's tests were again written before the change they cover and failed first (the late look, the failure reasons, the closed pull request, the property-named state). The ones that guard what must keep working (a clean pull request still approved and merged, anunknownthat settles still merging,approvealone with--force) passed on both, as intended.admin-pr-reviews-cli138 pass,pr-review-approve72,pr-review-next.unit17,pr-reviews-render.unit13,admin-pr-reviews-start-cli31,admin-route-inventory.unit4,api-export-surface.unit10,changelog-format.unit6,adr-index.unit8; 0 failures. The same seven pr-reviews suites on cleanorigin/devwere 234 pass, 0 fail, so this branch adds 51 tests to them.bun run typecheckandbun run lintclean; Biome clean on every changed file.bun run src/index.tsagainst the repository'sBun.serveGitHub stand-in and the real admin router over bun:sqlite; no mocks. They assert on what the administrator's token wrote (POST reviews,PUT merge, comments, closes), not on text alone. The stand-in can now omitmergeable_state, and change the state, head, status or openness after the administrator's first read.mergeable_stateread as clean (infetchPullRequestand inmergeCheckOf);--forceskipping the early check; the late look removed, inapproveand innext; the late look reading a stale state (in both callers, and in the helper); the late look also running without--merge; the late look not labelled; the open check removed from the re-read; the property-name lookup restored; the failure reasons collapsed back tounknown; a failed read read as clean; a moved head not detected; the early check removed, or moved after the confirmation;unstable,unknownor a missing state treated as clean;cleanrefused;ynot gated on the check, or--forceskipping it; the look before the merge removed; the approve-only hint and the advice wrong in each direction. One mutant (--forceskipping the early check) survived the first run because the late look still wrote nothing; the tests now assert the refusal came from the early check, and it is killed. The delta review's two findings are covered the same way: the late look moved above the confirmation inapprove, and a late look taken when the card is shown innext, both fail the new tests; the advice text reverted fornext, for a moved head and forapprove, and a not-read state read as clean, are also killed.Not verified
pr-reviewswrite command was run. That a held review actually readsunstableis still the expectation recorded in ADR 0092, not an observation.--yesthey see "Not approved." from the non-interactive path).unknownthat never settles wait out the real re-ask interval (about 4 seconds each), and a few others wait one or two seconds, so the CLI suite is slower than before.For the maintainer
blockedbefore the administrator's approval andcleanafter it.--mergeandyused to approve and merge such a pull request; they now refuse it. The ruleset applied to published datasets requires none (required_approving_review_count: 0, ADR 0001) and the four legacy repositories use classic branch protection that requires none, so nothing is refused today for this reason.unstablewhen both required checks pass (the other option in ADR 0092's open item) is still open and untouched here.