Skip to content

Add wait_for_merge_gate for a terminal CI merge verdict - #149

Open
bobby-nandigam wants to merge 1 commit into
prooflinedev:mainfrom
bobby-nandigam:merge-gate-wait
Open

bobby-nandigam wants to merge 1 commit into
prooflinedev:mainfrom
bobby-nandigam:merge-gate-wait

Conversation

@bobby-nandigam

Copy link
Copy Markdown

What this adds

wait_for_merge_gate on both ProoflineClient and AsyncProoflineClient: it waits for a pull request's merge gate to reach a terminal verdict and returns a typed MergeGateDecision a CI job can act on directly.

Who it helps

Anyone gating merges with Proofline from CI. The merge gate is a separate state machine from the review itself — REQUESTED/EVALUATING before a verdict, then ALLOWED/BLOCKED/BYPASSED/SUPERSEDED — so a review can be COMPLETED while the gate is still evaluating. wait_for_review tells you the review finished; it does not tell you whether the head may merge. Until now a CI script had to read review.merge_gate by hand, interpret the GateStatus/Outcome enums, poll for the decision, and re-implement head pinning. This turns that into one call that returns a clear pass/block.

decision = client.wait_for_merge_gate(org, review_id, head_commit_sha=head)
if not decision.allowed:
    raise SystemExit(f"Merge blocked: {decision.status}")

Decisions

  • Fails closed. allowed is True only on an ALLOWED decision. BYPASSED (a human override), SUPERSEDED, an undecided gate at the deadline (TIMED_OUT), and a head with no captured gate (UNAVAILABLE) all read as not-mergeable. A gate is a safety control, so the conservative default is the correct one.
  • Surfaces the server's verdict; invents no policy. The decision is read straight from the recorded PullRequestMergeGate (verdict, blocking_severity, blocking_finding_count, policy_version, reason_code, raw gate). The SDK does not re-derive what blocks.
  • Reuses the proven wait discipline. Same budget, backoff, retry-deadline handling, and head_commit_sha pinning as wait_for_review, so a gate pinned to another head is never reported as ALLOWED — the same correctness guarantee the existing wait makes.
  • Separation of concerns. Pure classification lives in a new gates.py with no I/O (mirroring outcomes.py); the clients only drive the polling loop. No change to proofline/_generated/ or the OpenAPI contract.

Verification

  • ruff check, ruff format --check, and mypy are all clean.
  • Added parametrized sync + async tests covering the EVALUATING→ALLOWED poll, BLOCKED with blocking metadata, BYPASSED/SUPERSEDED, an absent gate on a settled review, a head mismatch, and an undecided-at-deadline timeout.
  • Full suite: 238 passed.

A review completing is not the merge gate deciding: the gate is its own
state machine (REQUESTED and EVALUATING before a verdict, then ALLOWED,
BLOCKED, BYPASSED or SUPERSEDED), so a completed review can still be
evaluating and wait_for_review does not report the gate outcome a CI job
actually needs.

Add wait_for_merge_gate to the sync and async clients. It polls with the
same budget, backoff, retry-deadline, and head-pinning discipline as
wait_for_review, and returns a typed MergeGateDecision read from the
server's recorded gate: a frozen verdict plus allowed, blocking_severity,
blocking_finding_count, policy_version, reason_code, and the raw gate.

allowed fails closed, true only on an ALLOWED decision, so BYPASSED,
SUPERSEDED, an undecided gate at the deadline (TIMED_OUT), and a head with
no captured gate (UNAVAILABLE) never read as mergeable. A gate pinned to
another head is UNAVAILABLE, never ALLOWED.

Classification lives in a separate gates module with no I/O, covered by
parametrized sync and async tests, and documented in the README.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant