Repository navigation
pr-status: look up PR runs by head SHA and load job logs on gh 2.97+ - #101707
Merged
Merged
Conversation
`node scripts/pr-status.js <pr>` could report a clean result for a PR whose CI failed. Runs were looked up by branch name, and fork PRs can share one: two forks pushing `fix/foo` both get runs on branch `fix/foo`, and fork runs list no pull_requests, so the script could pick the other PR's run. It now looks runs up by the PR's head SHA (`headRefOid`), and keeps the branch query for the current-branch case without a PR. Since gh 2.97, `gh api` refuses to print a raw response that contains an ESC byte unless `--allow-escape-sequences` is passed, and every Actions job log contains them. Every job file read "Logs not available", and the flaky-test check silently found nothing. The script now passes the flag when `gh api --help` lists it (older gh rejects it as unknown), strips all terminal escape sequences from logs before parsing or writing them, and reports a failed log download in index.md, the job file and the Known Flaky Tests section instead of hiding it.
Contributor
|
Vercel Agent couldn’t finish reviewing your changes. The pull request head changed before checkout completed. Resolved issues (1)
Review stepsPreparing the workspace |
Contributor
Tests PassedCommit: d36f8a7 |
jamiboym
added a commit
that referenced
this pull request
Nov 18, 2026
#101714) ## Summary `node scripts/pr-status.js` decided a run was clean by counting failed jobs and never looked at the run's conclusion. A finished run can have no failed jobs without passing: it can be waiting for a maintainer to approve a fork PR's workflows (`action_required`), cancelled before any job failed, unable to start because of a broken workflow file (`startup_failure`), skipped, or stale. Each of those printed "No failed jobs found" and produced the same `index.md` as a passing run, apart from the `Status:` line. Only `success` now reads as clean. For any other conclusion with no failed jobs, `index.md` opens with a "CI did not pass" note that names the reason, the title becomes "CI Status Report", and the console says the run did not pass. Conclusions without a specific note, including any GitHub adds later, get a generic one. Runs that list failed jobs are unchanged. Every status other than `completed` now counts as unfinished. Before, only `queued` and `in_progress` did, so `waiting`, `pending` and `requested` runs fell into the "No failed jobs found" path and `--wait` didn't wait for them. The script now runs `main()` only when invoked directly and exports `describeUnpassedRun`, `generateIndexMd` and `isRunUnfinished`, so `test/unit/pr-status-run-status.test.ts` can check how each status and conclusion is reported. This is independent of [#101707](#101707), which makes the script pick the PR's own run and load job logs again. Both edit `scripts/pr-status.js` in different places. ## Verification - `test/unit/pr-status-run-status.test.ts` covers every status and conclusion. Making the `action_required` case read clean again fails it. - `node scripts/pr-status.js <pr> --skip-flaky-check` on live runs: - [#101643](#101643): an `action_required` run shows the note in `index.md` and on the console. Without #101707, the branch lookup picked [#101628](#101628 newer run on the shared branch name, which is also waiting for approval. - [#101304](#101304): a cancelled run with 1 failed job lists the failure, without the note. - [#101701](#101701): a passing run still prints "No failed jobs found", without the note. - prettier, eslint and ast-grep on `scripts/pr-status.js`. <!-- NEXT_JS_LLM --> 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Run main() only when the script is invoked directly and export its helpers. Split the runs URL into workflowRunsPath and the --help check into rawOutputFlagsFromHelp, and let getJobLogs take the gh runner and flags, so a unit test covers the head-SHA lookup, the --allow-escape-sequences flag, escape stripping and reported download errors without calling gh. A runner argument works on Windows, where a fake gh script on PATH would not.
…cutt-894702 # Conflicts: # scripts/pr-status.js
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
node scripts/pr-status.js <pr>could report a clean result for a PR whose CI had failed. Both bugs below came up while triaging vercel/next.js#101628.Wrong run for fork PRs that share a branch name
The script listed runs with
actions/runs?branch=<name>and took the newestbuild-and-testrun. Fork PRs vercel/next.js#101628 and vercel/next.js#101643 both come from a branch namedfix/proxy-rewrite-status-cache-components, and runs for fork PRs have an emptypull_requestslist. Sonode scripts/pr-status.js 101628reported the other PR's unapproved run (action_required, "No failed jobs found") rather than its own failed run.When the PR is known (passed as an argument or found for the current branch), the script now lists runs by the PR's head commit (
headRefOid,actions/runs?head_sha=). Without a PR it still queries by branch.No job logs with gh 2.97 or later
Since gh 2.97 (GHSA-3m3g-3wcr-px46),
gh apirefuses to print a raw response that contains an ESC byte unless--allow-escape-sequencesis passed, and every Actions job log contains them. The script caught the error, so every job file said "Logs not available" and the flaky-test check found 0 flaky tests without saying why.getJobLogsnow serves both the PR's failed jobs and the flaky check. It passes--allow-escape-sequenceswhengh api --helplists it; older gh rejects the flag as unknown, so it is left out there.stripAnsinow removes all of them (CSI, OSC, other escapes, and any stray ESC byte) before the logs are parsed or written to the output files. Previously it removed only CSI sequences that end in a letter.index.mdlists each failure with gh's error under "Log Fetch Failures", the job file explains why it has no sections, and the Known Flaky Tests section warns when it couldn't read some logs or couldn't list runs.To make this testable, the script now runs
main()only when invoked directly and exports its helpers. The runs URL (workflowRunsPath) and the--helpcheck (rawOutputFlagsFromHelp) are their own functions, andgetJobLogsaccepts the gh runner and flags, sotest/unit/pr-status-ci-logs.test.tsruns without gh, on Windows too.A finished run that didn't pass but has no failed jobs, such as one waiting for approval, still reads as clean. A separate PR handles that.
The
pr-status-triageskill docs don't describe how runs are picked or logs are fetched, so they're unchanged.Verification
test/unit/pr-status-ci-logs.test.ts: undoing any one fix (head-SHA lookup, the flag, escape stripping, reported download errors) fails a test.node scripts/pr-status.js 101628with gh 2.103.3 reports run 43221853884 (attempt 2) with 4 failed jobs. The three deploy jobs' test files contain thevercel linkfailure ("No existing credentials found"), no output file contains an ESC byte, and the flaky check read all 21 logs from other branches.ghonPATH(no flag ingh api --help, rejects it as unknown, prints raw logs) never passes the flag and produces output identical to the gh 2.103.3 run.ghwhose log downloads fail with HTTP 404,index.mdlists the 4 failures, each job file names the error, and Known Flaky Tests warns that 21 of 21 logs couldn't be fetched.node scripts/pr-status.js --skip-flaky-checkon a branch without a PR still queries by branch, and--comments-onlystill works.stripAnsichecked against colors, private-mode CSI, OSC 8 hyperlinks (ST and BEL terminators), charset escapes, malformed and unterminated sequences, and JSON text containing an escaped\u001b.scripts/pr-status.js.🤖 Generated with Claude Code