4040 with :
4141 script : |
4242 const gateName = 'codex-review-gate';
43- const gateVersion = 'v8 ';
43+ const gateVersion = 'v9 ';
4444 const stateName = 'codex-review-quota-state';
4545 const codexLogins = new Set([
4646 'chatgpt-codex-connector',
@@ -307,6 +307,53 @@ jobs:
307307 return created.data;
308308 }
309309
310+ async function ensureAmbiguousSharedHeadGate(pulls) {
311+ const headSha = pulls[0].head.sha;
312+ const run = await latestGateRun(headSha);
313+ const externalId = `${gateVersion}:ambiguous`;
314+ const details = pulls
315+ .slice()
316+ .sort((a, b) => a.number - b.number)
317+ .map((pull) => `#${pull.number} @ ${pull.base.sha}`)
318+ .join(', ');
319+ const output = {
320+ title: 'Codex review blocked by shared head',
321+ summary: [
322+ 'Multiple reviewable pull requests reuse this head commit against different base commits.',
323+ 'A commit-scoped required check cannot safely represent those different diffs.',
324+ `Conflicting pull requests: ${details}`,
325+ 'Give the pull requests distinct head commits, close one, or convert one to draft before Codex review can proceed.',
326+ ].join('\n'),
327+ };
328+
329+ if (run?.external_id === externalId) {
330+ await github.rest.checks.update({
331+ owner,
332+ repo,
333+ check_run_id: run.id,
334+ status: 'completed',
335+ conclusion: 'failure',
336+ completed_at: now.toISOString(),
337+ output,
338+ });
339+ return run;
340+ }
341+
342+ const created = await github.rest.checks.create({
343+ owner,
344+ repo,
345+ name: gateName,
346+ head_sha: headSha,
347+ external_id: externalId,
348+ status: 'completed',
349+ conclusion: 'failure',
350+ completed_at: now.toISOString(),
351+ details_url: `${context.serverUrl}/${owner}/${repo}/pull/${pulls[0].number}`,
352+ output,
353+ });
354+ return created.data;
355+ }
356+
310357 function requestCommentIdForRun(run) {
311358 const summary = String(run.output?.summary || '');
312359 const match = summary.match(/^Request comment: (\d+)$/m);
@@ -571,6 +618,19 @@ jobs:
571618 !pull.draft &&
572619 pull.base.ref === defaultBranch,
573620 );
621+ const reviewablePullsByHead = new Map();
622+ for (const pull of reviewablePulls) {
623+ const siblings = reviewablePullsByHead.get(pull.head.sha) || [];
624+ siblings.push(pull);
625+ reviewablePullsByHead.set(pull.head.sha, siblings);
626+ }
627+ const ambiguousHeadShas = new Set();
628+ for (const [headSha, siblings] of reviewablePullsByHead) {
629+ const baseShas = new Set(siblings.map((pull) => pull.base.sha));
630+ if (baseShas.size < 2) continue;
631+ ambiguousHeadShas.add(headSha);
632+ await ensureAmbiguousSharedHeadGate(siblings);
633+ }
574634
575635 // A trusted manual review request invalidates an earlier success
576636 // immediately, even while the PR is draft. Draft PRs are excluded
@@ -583,7 +643,10 @@ jobs:
583643 pull.state === 'open' &&
584644 pull.base.ref === defaultBranch,
585645 );
586- if (triggeringPull) {
646+ if (
647+ triggeringPull &&
648+ !ambiguousHeadShas.has(triggeringPull.head.sha)
649+ ) {
587650 const triggerRun = await latestGateRun(triggeringPull.head.sha);
588651 const triggerVersionMismatch = Boolean(
589652 triggerRun &&
@@ -620,9 +683,13 @@ jobs:
620683 const inspectedNonReviewableSiblings = new Set();
621684
622685 for (const pull of reviewablePulls) {
686+ if (ambiguousHeadShas.has(pull.head.sha)) continue;
623687 const triggeringRequestCommentId =
624688 eventPullNumber === pull.number ? triggeringReviewCommandId : null;
625689 let run = await latestGateRun(pull.head.sha);
690+ const ambiguousRun = Boolean(
691+ run && run.external_id === `${gateVersion}:ambiguous`,
692+ );
626693 const versionMismatch = Boolean(
627694 run && !String(run.external_id || '').startsWith(`${gateVersion}:`),
628695 );
@@ -631,7 +698,7 @@ jobs:
631698 !versionMismatch &&
632699 run.external_id !== `${gateVersion}:${pull.base.sha}`,
633700 );
634- if (versionMismatch) {
701+ if (ambiguousRun || versionMismatch) {
635702 run = await createPendingGate(
636703 pull,
637704 false,
0 commit comments