From 4059949762ccc29cfd224bdcb9e9fe9faff6d5b4 Mon Sep 17 00:00:00 2001 From: Keavon Chambers Date: Fri, 4 Dec 2026 22:04:32 -0800 Subject: [PATCH] Make the PR title review pass a run whose title changed while it ran --- .github/pr-title-review/gather.ts | 7 +++++-- .github/pr-title-review/report.ts | 7 ++++--- .github/workflows/pr-title-review.yml | 7 ++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/pr-title-review/gather.ts b/.github/pr-title-review/gather.ts index c98575a78a..2f583ebfb8 100644 --- a/.github/pr-title-review/gather.ts +++ b/.github/pr-title-review/gather.ts @@ -29,6 +29,8 @@ const DAILY_LIMIT_PER_CONTRIBUTOR = 40; const MAX_RUN_PAGES = 10; // The workflow step that fails only when a run reached a verdict against its title, by the end of its name const VERDICT_STEP_NAME = "Fail for the title's verdict"; +// The workflow step that passes a run whose title changed while it ran, without a verdict, by the end of its name +const SUPERSEDED_STEP_NAME = "Pass for a newer run's review"; const MAX_VERDICT_LOOKUPS = 5; // How much of the PR's changes accompany the title, which keeps the message under about 20,000 tokens @@ -175,14 +177,15 @@ async function listBranchRuns(workflowId: number, before?: number): Promise { for (let i = 0; i < Math.min(finishedRunsNewestFirst.length, MAX_VERDICT_LOOKUPS); i++) { const run = finishedRunsNewestFirst[i]; - if (run.conclusion === "success") return run; const { jobs } = await github<{ jobs: { steps?: { name: string; conclusion: string | null }[] }[] }>("GET", `/repos/${repository}/actions/runs/${run.id}/jobs`); const steps = jobs.flatMap((job) => job.steps || []); + if (steps.some((step) => step.name.endsWith(SUPERSEDED_STEP_NAME) && step.conclusion === "success")) continue; + if (run.conclusion === "success") return run; if (steps.some((step) => step.name.endsWith(VERDICT_STEP_NAME) && step.conclusion === "failure")) return run; } diff --git a/.github/pr-title-review/report.ts b/.github/pr-title-review/report.ts index bb76d228e7..cc09ca831f 100644 --- a/.github/pr-title-review/report.ts +++ b/.github/pr-title-review/report.ts @@ -37,6 +37,7 @@ const pullRequestNumber = readEvent().pull_request.number; const decision = readDecision(); const retried = RETRIED_OUTCOMES.includes(decision.outcome); const passed = PASSING_OUTCOMES.includes(decision.outcome); +const superseded = decision.outcome === "superseded"; // New feedback replaces earlier comments so the latest is at the bottom of the conversation, while carried-over and retried outcomes leave them be if (decision.outcome !== "unchanged" && decision.outcome !== "still_approved" && !retried) { @@ -47,10 +48,10 @@ if (decision.outcome !== "unchanged" && decision.outcome !== "still_approved" && } } -console.log(`::${passed ? "notice" : "error"}::${ANNOTATIONS[decision.outcome]}`); +console.log(`::${passed || superseded ? "notice" : "error"}::${ANNOTATIONS[decision.outcome]}`); -// The workflow fails a different step for a verdict against the title than for an outcome to retry, which later runs read back to tell them apart -const result = passed ? "approved" : retried ? "retry" : "verdict"; +// Later runs tell verdicts, retries, and superseded runs apart by which of the workflow's last steps each one ran +const result = passed ? "approved" : superseded ? "superseded" : retried ? "retry" : "verdict"; fs.appendFileSync(requireEnvironment("GITHUB_OUTPUT"), `result=${result}\n`); function readDecision(): Decision { diff --git a/.github/workflows/pr-title-review.yml b/.github/workflows/pr-title-review.yml index fe899cfa1f..873577f59c 100644 --- a/.github/workflows/pr-title-review.yml +++ b/.github/workflows/pr-title-review.yml @@ -64,7 +64,12 @@ jobs: if: ${{ !cancelled() && steps.report.outputs.result == 'verdict' }} run: exit 1 + # A run whose title changed mid-run passes and leaves the check to the newer run, which skips it by this name (see `SUPERSEDED_STEP_NAME` in `gather.ts`) + - name: ⏭️ Pass for a newer run's review + if: ${{ !cancelled() && steps.report.outputs.result == 'superseded' }} + run: echo "A newer run reviews the changed title" + # Later runs review the title again after this failure, as they do when a step above fails unexpectedly - name: 🔁 Fail without a verdict - if: ${{ !cancelled() && steps.report.outputs.result != 'verdict' && steps.report.outputs.result != 'approved' }} + if: ${{ !cancelled() && steps.report.outputs.result != 'verdict' && steps.report.outputs.result != 'approved' && steps.report.outputs.result != 'superseded' }} run: exit 1