Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions pr-gate/decide.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,28 @@ const MARKER_RE = /^\s*starlight-signoff:\s*harness=(\S+)\s+verdict=(\S+)\s+sha=
const CHECKER_RE = /^\s*Checker:\s*([a-z0-9_-]+?)(?:-cloud)?\s*[·|-]\s*head\s+([0-9a-fA-F]{7,40})\s*[·|-]\s*verdict\s+(PASS|FAIL|BLOCK)\b/i;
const CODEX_CLEAN_RE = /didn'?t find any major issues/i;
const SEVERE_RE = /\bp[01]\b|p[01] badge/i;
// Full-media text excludes hidden metadata, but also omits image alt labels
// (including real P1 badges). Recover alt text only from rendered image tags.
// Tokenize comments and complete quoted tags so neither hidden images nor an
// "alt" example inside another attribute can manufacture a finding.
const HTML_TOKENS = /<!--(?:>|->|[\s\S]*?(?:-->|--!>|$))|<![^>]*>|<\?[^>]*>|<\/?[A-Za-z](?:[^"'<>]|"[^"]*"|'[^']*')*>/g;
const HTML_ATTRIBUTES = /([^\s"'<>\/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
function reviewText(item) {
if (typeof item.bodyText !== 'string' || typeof item.bodyHTML !== 'string') return null;
const labels = [];
for (const [tag] of item.bodyHTML.matchAll(HTML_TOKENS)) {
if (!/^<img(?=[\s/>])/i.test(tag)) continue;
for (const attr of tag.slice(4, -1).matchAll(HTML_ATTRIBUTES)) {
if (attr[1].toLowerCase() !== 'alt') continue;
labels.push((attr[2] ?? attr[3] ?? attr[4] ?? '').replace(/&#(?:x([0-9a-f]+)|([0-9]+));/gi, (_, hex, dec) => {
const code = Number.parseInt(hex ?? dec, hex ? 16 : 10);
return code > 0 && code <= 0x10ffff && !(code >= 0xd800 && code <= 0xdfff) ? String.fromCodePoint(code) : '\ufffd';
}));
break; // HTML's first alt attribute wins.
}
}
return [item.bodyText, ...labels].join('\n');
}

// GitHub's own bot accounts are the only reviewer identity an agent cannot type its way into.
// Exact logins on purpose: a substring match would accept any app whose name contains "codex".
Expand All @@ -60,18 +82,24 @@ export function collectSignoffs({ comments = [], reviews = [], headSha }) {
}
// Bot comments are not sign-offs: they carry no commit id, and a "no major issues" line can sit
// beside a P1 in the same comment. Only commit-bound bot reviews pass. A bot comment that names
// a P0/P1 against the head still blocks.
// a visible P0/P1 against the head still blocks, even if metadata names the head.
// That SHA can associate a block, but metadata can never turn a comment into a pass.
const h = botHarness(c.user);
if (h && SEVERE_RE.test(c.body || '') && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
out.push({ harness: h, verdict: 'block', sha: head, via: 'bot-comment', trusted: true });
if (h && head.length >= 7 && String(c.body).toLowerCase().includes(head.slice(0, 7))) {
const body = reviewText(c);
if (body === null || SEVERE_RE.test(body)) {
out.push({ harness: h, verdict: body === null ? 'unreadable' : 'block', sha: head, via: 'bot-comment', trusted: true });
}
}
}
for (const r of reviews) {
const h = botHarness(r.user);
if (!h || r.state === 'DISMISSED' || r.state === 'PENDING') continue;
const body = String(r.body || '');
const body = reviewText(r);
let verdict = null;
if (r.state === 'CHANGES_REQUESTED' || SEVERE_RE.test(body)) verdict = 'block';
if (r.state === 'CHANGES_REQUESTED') verdict = 'block';
else if (body === null) verdict = 'unreadable';
else if (SEVERE_RE.test(body)) verdict = 'block';
else if (r.state === 'APPROVED' || CODEX_CLEAN_RE.test(body)) verdict = 'pass';
// A COMMENTED review that neither approves nor says it is clean is not a verdict either way;
// its inline findings surface as unresolved threads.
Expand Down Expand Up @@ -148,6 +176,8 @@ export function decide(f) {
reasons.push('no linked intent: reference the issue, board item or ruling this PR serves');
}

const unreadable = signoffs.filter((s) => s.verdict === 'unreadable' && onHead(s));
if (unreadable.length) reasons.push(`review text unavailable on this commit from ${[...new Set(unreadable.map((s) => s.harness))].join(', ')}`);
const blocks = signoffs.filter((s) => (s.verdict === 'block' || s.verdict === 'fail') && onHead(s) && s.harness !== author);
const valid = signoffs.filter((s) => s.verdict === 'pass' && onHead(s) && s.harness !== author);
if (blocks.length) reasons.push(`blocked on this commit by ${[...new Set(blocks.map((b) => b.harness))].join(', ')}`);
Expand Down
Loading
Loading