Wait for a pull request's checks with fj pr checks --watch (CLS-1328) #340
Loading…
Reference in a new issue
No description provided.
Delete branch "stephen/cls-1328-pr-checks-watch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds
fj pr checks N --watchfor CLS-1328. A self-hosted user asked for a way to block a script on a pull request's CI and get the outcome back. Today that means hand-rolling a loop overfj pr checks.The command waits for every check on the head commit. Each way the wait can end has its own exit code:
outcomesuccess--grace.failedtimeout--timeout(default30m) passed with checks still pending.no_checks--grace(default2m).--jsonprints theoutcomefield on every exit path, so a script can tell a failed check from fj failing (both exit 1, which keepsghparity).What counts as a check:
Skipped jobs count as passing, and the summary says how many there were.
A failure ends the wait at once. A pass waits until the head has been watched for
--graceand no new run or status has appeared for--grace. Forgejo creates a pull request's runs after its test merge, so underon: [push, pull_request]the push run can be green before the pull_request runs exist. The cost is that a pass takes at least--grace(default2m), even on a pull request that is already green. If not every run for the commit could be read, the wait never passes and says why.Differences from
gh:--fail-fastis accepted and ignored, so gh-shaped scripts don't trip on an unknown flag.--timeoutand--graceare new.--intervaltakes seconds or30s/2m.Behavior while waiting:
--timeoutno longer than--graceis a usage error (2), since a pass could never come.--json.Every exit, errors included, prints each check's status, name, run number and elapsed time. A missing run is shown as
(none). Plain-words notes cover:waiting(no matching runner);Tests: wiremock cases cover delayed enqueue across several runs and jobs, fail-fast, cancelled, never-enqueued until timeout, no checks within grace, a moved head, a retried 503, a missing PR, a server that ignores the
head_shafilter, a green run followed by a late failing one, an incomplete run list, a run rerun mid-wait, a lost later page, a markup body (retried), JSON of the wrong shape (fails fast) and a 403 on runs. There are also unit tests for judging, jobs sharing a name, rerun attempts, status dedupe and duration parsing.scripts/e2e-smoke.shgets a bounded read-only wait on the test repo's newest PR. It accepts any outcome but requires the wait to report one.I also ran it live against this repo: #337 exited 0 with run #672's three jobs and their times, matching
fj run view, and an open PR exited 6 at the timeout. The live run found that Forgejo sends botheventandtrigger_event, which a serde alias had collided on. That is fixed, and the fixtures now carry both fields.Docs: help text,
docs/exit-codes.md(new section),docs/gh-to-fj.mdand CHANGELOG.Clippy, fmt and the touched tests were run locally. The full suite ran in the pre-push hook.
Follow-up, not in this PR: when the run list is incomplete, fall back to commit statuses instead of never passing.