Skip to content

Commit 3af1ad3

Browse files
committed
fix(ci): count only the pull requests at the head, not near it
The guard requiring exactly one open pull request was written for PRs that share a head commit, but the endpoint it reads is broader than that. Per the API reference it lists pull requests ASSOCIATED with a commit, which for a commit outside the default branch means any open PR whose branch contains it. Stacking one branch on another and opening both therefore counts as two, and the lower one fails closed on a state its author cannot clear by pushing, because pushing does not remove the PR above it. That is the same unfixable red this workflow refuses to inflict elsewhere, and it costs a contributor the one thing fail-closed is supposed to protect: a way forward. Filter the associations by head SHA as well as state. Two pull requests genuinely pointing at the same commit still fail closed, which is the case the guard exists for and the case where a verdict computed for one PR would otherwise satisfy the other. Checked against all four shapes: stacked branches now resolve, a real collision still refuses, a lone PR resolves, and an association with no open PR at the head still refuses. Assisted-By: Claude <[email protected]> Signed-off-by: Aleksei Sviridkin <[email protected]>
1 parent 806b66f commit 3af1ad3

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

‎.github/workflows/e2e-fork.yaml‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,26 @@ jobs:
195195
github.rest.repos.listPullRequestsAssociatedWithCommit,
196196
{ owner, repo, commit_sha: HEAD_SHA, per_page: 100 },
197197
);
198-
// Exactly one, not the first one: a single branch may have several
199-
// open PRs against different base branches, and every decision
200-
// below is taken from whichever PR this picks — the merge-ref
201-
// checkout, the docs-only verdict, the TIA file list — while the
202-
// status is written to the head SHA all of them share. Taking the
203-
// first would let a verdict computed for one PR satisfy another,
204-
// including a docs-only green for a PR whose own base sees code.
205-
// The HEAD^2 == head_sha assert downstream cannot catch it: that
206-
// holds for every PR sitting on the commit. Fail closed, and name
207-
// the count so the state is diagnosable from the status alone.
208-
const open = assoc.filter(p => p.state === 'open');
198+
// Exactly one PR AT this head, not the first association. A single
199+
// branch may have several open PRs against different base branches,
200+
// and every decision below is taken from whichever PR this picks:
201+
// the merge-ref checkout, the docs-only verdict, the TIA file list,
202+
// while the status is written to the head SHA all of them share.
203+
// Taking the first would let a verdict computed for one PR satisfy
204+
// another, including a docs-only green for a PR whose own base sees
205+
// code. The HEAD^2 == head_sha assert downstream cannot catch that:
206+
// it holds for every PR sitting on the commit.
207+
//
208+
// The head_sha filter is what keeps the guard as narrow as its
209+
// reason. This endpoint returns PRs ASSOCIATED with the commit,
210+
// which per the API docs means any open PR whose branch contains
211+
// it, not only those pointing at it. Without the filter, stacking
212+
// one branch on another and opening both PRs counts as two, and
213+
// the lower PR fails closed on a state its author cannot clear by
214+
// pushing. That is the same unfixable red this workflow refuses to
215+
// inflict elsewhere. Two PRs genuinely at the same head still fail
216+
// closed, which is the case the guard exists for.
217+
const open = assoc.filter(p => p.state === 'open' && p.head && p.head.sha === HEAD_SHA);
209218
if (open.length !== 1) {
210219
await decide('failure', `expected exactly one open PR for ${HEAD_SHA}, found ${open.length}`);
211220
return;

0 commit comments

Comments
 (0)