mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-24 09:01:28 +01:00
Fix ready notes, landing decisions, release PR descriptions and squash messages (GST-3343) (#4596)
Landing a ready PR now reads its gate decisions from the PR's ready note, and the ready note, a reopened release PR and a stacked PR's squash message now say the right thing. Each of these stopped a landing or left a wrong public record until someone fixed it by hand; the goal is unattended shipping that lands on its own. Nothing to do as a reader. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: p1/red-team#1 reader=red-team
This commit is contained in:
1 parent
b281effa07
commit
7fe1900f8b
18 files changed
+304
-42
No files matched your search
@@ -10,7 +10,9 @@
|
||||
* the writer's hash reproduces) and its `digest` over those fields, so a hand-typed or edited row is ignored. The digest catches
|
||||
* edits; it is not authentication: a same-user lane can compute it too. What authorizes a disposition is the lander's explicit
|
||||
* `--accept-gate-disposition <id>` (`gateAcceptance`, run by `gstack-ship-queue land --pin` and `verify --pin`), re-derived from
|
||||
* the store at the pin, never from the receipt or the PR body (docs/ship-policy.md#gate-dispositions).
|
||||
* the store at the pin, never from the receipt or the PR body (docs/ship-policy.md#gate-dispositions). A store lives on the machine
|
||||
* that recorded the row, so `ready` also copies each applied non-security row, signed and whole, into the READY note on the
|
||||
* notes ref, and a lander on another machine reads those rows beside its own store under the same checks (#4581).
|
||||
*/
|
||||
import { createHash } from 'node:crypto';
|
||||
import { spawnSync } from './spawn-sync';
|
||||
@@ -80,7 +82,7 @@ export function readGateDispositions(cwd: string, env: Env = process.env): GateD
|
||||
* full clone a row whose head commit is gone (a rewritten and collected branch, a reused name) is not applied: the pin's history
|
||||
* is all present, so a missing commit cannot be in it.
|
||||
*/
|
||||
export function appliedGateDispositions(cwd: string, o: { branch?: string; pin: string; env?: Env }): { applied: GateDisposition[]; loc: StoreLocation } {
|
||||
export function appliedGateDispositions(cwd: string, o: { branch?: string; pin: string; env?: Env; noted?: readonly ApprovalRow[] }): { applied: GateDisposition[]; rows: ApprovalRow[]; loc: StoreLocation } {
|
||||
const loc = locate({ cwd, env: o.env ?? process.env, branch: o.branch });
|
||||
if ('code' in loc) throw new Error(loc.message);
|
||||
const git = (...args: string[]) => spawnSync('git', args, { cwd, encoding: 'utf8', timeout: 10_000 });
|
||||
@@ -94,7 +96,10 @@ export function appliedGateDispositions(cwd: string, o: { branch?: string; pin:
|
||||
if (r.status === 1 || git('cat-file', '-e', `${head}^{commit}`).status !== 0) return false;
|
||||
throw new Error(`git merge-base --is-ancestor ${head.slice(0, 12)} ${o.pin.slice(0, 12)} failed (${(r.stderr ?? r.error?.message ?? '').trim().slice(0, 120) || `exit ${r.status}`})`);
|
||||
};
|
||||
return { applied: gateDispositions(readRecord(loc).rows, loc.branch).filter(d => contains(d.head)), loc };
|
||||
const byId = new Map([...(o.noted ?? []), ...readRecord(loc).rows].map(r => [r.id, r]));
|
||||
const rows = [...byId.values()].sort((a, b) => String(a.recorded_at).localeCompare(String(b.recorded_at)));
|
||||
const applied = gateDispositions(rows, loc.branch).filter(d => contains(d.head));
|
||||
return { applied, rows: applied.map(d => byId.get(d.approval)!), loc };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,18 +163,19 @@ export type GateAcceptanceCode = Extract<ResultCodeName, 'QUEUE_GATE_DISPOSITION
|
||||
* receipt's gate_dispositions or the PR body's `Gate disposition:` lines differ from them, and, with `accepted` (land and
|
||||
* verify; ready passes none), when an applied disposition is not accepted or an accepted id is not applied.
|
||||
*/
|
||||
export function gateAcceptance(o: { cwd: string; branch: string; pin: string; body: string; receipt?: ShipReceipt; accepted?: readonly string[]; env?: Env }):
|
||||
{ lines: string[]; applied: GateDisposition[]; failure?: { code: GateAcceptanceCode; message: string; fix: string } } {
|
||||
export function gateAcceptance(o: { cwd: string; branch: string; pin: string; body: string; receipt?: ShipReceipt; accepted?: readonly string[]; env?: Env; noted?: readonly ApprovalRow[] }):
|
||||
{ lines: string[]; applied: GateDisposition[]; noteRows?: ApprovalRow[]; failure?: { code: GateAcceptanceCode; message: string; fix: string } } {
|
||||
const fix = 'the lander reads each GATE_DISPOSITION line and reruns with --accept-gate-disposition <approval id> for each one it accepts; a receipt or body that differs from the store is rewritten by /ship at the pin (docs/troubleshooting.md#queue-gate-disposition)';
|
||||
let got: ReturnType<typeof appliedGateDispositions>;
|
||||
try { got = appliedGateDispositions(o.cwd, o); }
|
||||
catch (e: any) { return { lines: [], applied: [], failure: { code: 'QUEUE_GATE_DISPOSITION', message: `the gate dispositions for ${o.branch} at the pin cannot be derived (${e.message}); an unreadable store or a git error refuses, never reads as none`, fix } }; }
|
||||
const { applied, loc } = got;
|
||||
const noteRows = got.rows.filter(r => !isSecurityFinding(SCOPE.exec(r.scope)![1]!));
|
||||
const recorded = o.receipt?.gate_dispositions;
|
||||
const listed = recorded ?? [];
|
||||
const where = `the store at ${loc.mirror ?? loc.file}`;
|
||||
const where = `the store at ${loc.mirror ?? loc.file}${o.noted?.length ? ' with the READY note\'s rows' : ''}`;
|
||||
const lines = applied.map(d => `GATE_DISPOSITION: ${gateDispositionText(d)}`);
|
||||
if (!applied.length && !listed.length && !o.accepted?.length) return { lines, applied };
|
||||
if (!applied.length && !listed.length && !o.accepted?.length) return { lines, applied, noteRows };
|
||||
const problems: string[] = [];
|
||||
for (const d of applied) {
|
||||
const r = listed.find(l => l.approval === d.approval);
|
||||
@@ -182,8 +188,8 @@ export function gateAcceptance(o: { cwd: string; branch: string; pin: string; bo
|
||||
for (const d of applied) if (!o.accepted.includes(d.approval)) problems.push(`disposition ${d.approval} is not accepted (--accept-gate-disposition ${d.approval})`);
|
||||
for (const id of o.accepted) if (!applied.some(d => d.approval === id)) problems.push(`--accept-gate-disposition ${id} names no disposition the store applies at ${o.pin.slice(0, 12)}`);
|
||||
}
|
||||
lines.push(`GATE_DISPOSITIONS: applied=${applied.map(d => d.approval).join(',') || 'none'}${o.accepted ? ` accepted=${o.accepted.join(',') || 'none'}` : ''} store=${loc.mirror ?? loc.file}`);
|
||||
return problems.length ? { lines, applied, failure: { code: 'QUEUE_GATE_DISPOSITION', message: problems.join('; '), fix } } : { lines, applied };
|
||||
lines.push(`GATE_DISPOSITIONS: applied=${applied.map(d => d.approval).join(',') || 'none'}${o.accepted ? ` accepted=${o.accepted.join(',') || 'none'}` : ''} store=${loc.mirror ?? loc.file}${o.noted?.length ? ` ready_note_rows=${o.noted.length}` : ''}`);
|
||||
return problems.length ? { lines, applied, noteRows, failure: { code: 'QUEUE_GATE_DISPOSITION', message: problems.join('; '), fix } } : { lines, applied, noteRows };
|
||||
}
|
||||
|
||||
/** The disposition as public text may carry it: a security-class finding's fingerprint, reason and owner words stay in the approval record (GST-3076). */
|
||||
|
||||
+8
-1
@@ -246,7 +246,14 @@ export function readyPlan(o: { cwd: string; env: Env; body: string; policyValue?
|
||||
const own = parsePlanLine(o.body);
|
||||
const fromFinish = !own && o.finishLine ? parsePlanLine(o.finishLine) : null;
|
||||
const decl = own ?? fromFinish;
|
||||
const mark = (res: PlanResolution): PlanResolution => (fromFinish && res.ok ? { ok: true, record: { ...res.record, from: 'finish' }, summary: `${res.summary} (from /ship finish's plan record; the PR body has no Plan: line)` } : res);
|
||||
const mark = (res: PlanResolution): PlanResolution => {
|
||||
if (!fromFinish || !res.ok) return res;
|
||||
const { row_id, ...rest } = res.record;
|
||||
const record: PlanRecord = rest.state === 'approved'
|
||||
? { ...rest, line: publicPlanLine(fromFinish, res), ref: RECORD_ID.test(rest.ref ?? '') ? rest.ref : planRecordId(row_id!), from: 'finish' }
|
||||
: { ...rest, line: `Plan: exempt: ${rest.reason}`, from: 'finish' };
|
||||
return { ok: true, record, summary: `${res.summary} (from /ship finish's plan record; the PR body has no Plan: line)` };
|
||||
};
|
||||
if (mode.mode === 'off') {
|
||||
const note = offNote(mode);
|
||||
const line = note ? { line: note } : {};
|
||||
|
||||
+15
-3
@@ -123,7 +123,7 @@ const defaultGh = (args: string[], cwd: string) => {
|
||||
/**
|
||||
* Stamp a fresh worktree of origin/<base> with gstack-restamp --release, commit only the stamped files (detached, so no
|
||||
* local branch is left behind), force-push the commit to release/<version> (a reopen after RELEASE_STAMP_INVALID
|
||||
* replaces the old release branch) and open the release PR. The Captain lands it with gstack-ship-queue land --pr <n> --pin <head> once its
|
||||
* replaces the old release branch) and open the release PR, or on a reopen rewrite the open PR's body to the new stamp's. The Captain lands it with gstack-ship-queue land --pr <n> --pin <head> once its
|
||||
* checks are green; the stable cut then tags the new version. --dry-run stamps and prints the diff, and creates nothing.
|
||||
*/
|
||||
export function openRelease(o: OpenOptions): OpenResult {
|
||||
@@ -168,7 +168,8 @@ export function openRelease(o: OpenOptions): OpenResult {
|
||||
].join('\n'));
|
||||
const posted = foldSections(body);
|
||||
const open = gh(['pr', 'list', '--head', branch, '--state', 'open', '--json', 'url,isCrossRepository', '--jq', '[.[] | select(.isCrossRepository | not)][0].url // ""'], dir);
|
||||
if (!(open.ok && open.out.trim()) && hostPublishes(o.env)) {
|
||||
const reopened = open.ok && !!open.out.trim();
|
||||
if (!reopened && hostPublishes(o.env)) {
|
||||
const view = gh(['repo', 'view', '--json', 'nameWithOwner,url'], dir);
|
||||
let dest: { repo: string; host: string } | undefined;
|
||||
try { const v = JSON.parse(view.out); dest = { repo: String(v.nameWithOwner ?? ''), host: new URL(String(v.url)).host }; } catch { dest = undefined; }
|
||||
@@ -176,8 +177,19 @@ export function openRelease(o: OpenOptions): OpenResult {
|
||||
lines.push(handOff({ op: 'pr-create', ...dest, base: o.base, head: branch, parts: [['title', `v${version} release`], ['body', posted]], env: o.env }).trimEnd(), `NEXT: gstack-ship-queue land --pr <n> --pin ${head} once the PR the host opens has green checks`);
|
||||
return { ok: true, version, branch, head, lines };
|
||||
}
|
||||
const pr = open.ok && open.out.trim() ? open : gh(['pr', 'create', '--base', o.base, '--head', branch, '--title', `v${version} release`, '--body', posted], dir);
|
||||
const pr = reopened ? open : gh(['pr', 'create', '--base', o.base, '--head', branch, '--title', `v${version} release`, '--body', posted], dir);
|
||||
if (!pr.ok) return fail('RELEASE_STAMP_INVALID', `gh pr create failed (${pr.err.trim().split('\n')[0]}); ${branch} is pushed, so open its PR by hand`);
|
||||
if (reopened && hostPublishes(o.env)) {
|
||||
const view = gh(['repo', 'view', '--json', 'nameWithOwner,url'], dir);
|
||||
let dest: { repo: string; host: string } | undefined;
|
||||
try { const v = JSON.parse(view.out); dest = { repo: String(v.nameWithOwner ?? ''), host: new URL(String(v.url)).host }; } catch { dest = undefined; }
|
||||
if (!view.ok || !dest?.repo) return fail('RELEASE_STAMP_INVALID', `cannot resolve the repository the release PR belongs to (gh repo view --json nameWithOwner,url: ${view.err.trim().split('\n')[0] || 'no repository'}); ${branch} is pushed with the new stamp, but its PR still has the old body, so replace the body with the host's PR tool`);
|
||||
const target = /\/pull\/(\d+)/.exec(pr.out.trim().split('\n').pop() ?? '')?.[1];
|
||||
lines.push(handOff({ op: 'pr-body', target, ...dest, parts: [['body', posted]], env: o.env }).trimEnd());
|
||||
} else if (reopened) {
|
||||
const edit = gh(['pr', 'edit', pr.out.trim().split('\n').pop() ?? '', '--body', posted], dir);
|
||||
if (!edit.ok) return fail('RELEASE_STAMP_INVALID', `gh pr edit failed (${edit.err.trim().split('\n')[0]}); ${branch} is pushed with the new stamp, but its PR still has the old body, so replace the body by hand`);
|
||||
}
|
||||
const url = pr.out.trim().split('\n').pop() ?? '';
|
||||
const n = /\/pull\/(\d+)/.exec(url)?.[1];
|
||||
lines.push(`RELEASE_PR: ${n ? `#${n} ` : ''}${url}`, `NEXT: gstack-ship-queue land --pr ${n ?? '<n>'} --pin ${head} once its checks are green`);
|
||||
|
||||
@@ -37,14 +37,16 @@ export interface DirectOptions { pr: string; pin: string; body?: string; dryRun?
|
||||
|
||||
/**
|
||||
* The pin's /ship receipt bound to it, and every owner gate disposition the approval store applies at the pin accepted by the
|
||||
* lander (lib/gate-dispositions.ts gateAcceptance, re-derived from the store, never from the receipt or the body): the one
|
||||
* check land --pin and verify --pin share, so the two cannot drift (docs/ship-policy.md#gate-dispositions).
|
||||
* lander (lib/gate-dispositions.ts gateAcceptance, re-derived from the store and the signed rows ready copied into the READY note at
|
||||
* the pin, never from the receipt or the body): the one check land --pin and verify --pin share, so the two cannot drift
|
||||
* (docs/ship-policy.md#gate-dispositions).
|
||||
*/
|
||||
export function pinAcceptance(ctx: QueueContext, info: Pick<DirectPr, 'body' | 'headRefName'>, pr: string, pin: string, accepted: readonly string[]): { lines: string[]; failure?: QueueFailure } {
|
||||
const receipt = bindShippedReceipt(ctx.repoRoot, `origin/${ctx.base}`, info.body ?? '', pr, [pin]);
|
||||
const lines = [receipt.line, ...(receipt.depthLine ? [receipt.depthLine] : []), ...(receipt.targetedLine ? [receipt.targetedLine] : [])];
|
||||
if (!receipt.ok) return { lines, failure: { code: receipt.code, message: receipt.message, fix: `run /ship at the pin, then gstack-ship-queue ready --pr ${pr}` } };
|
||||
const gates = gateAcceptance({ cwd: ctx.repoRoot, branch: info.headRefName, pin, body: info.body ?? '', receipt: receipt.receipt, accepted });
|
||||
const noted = loadReady(repoIdentity(ctx.repoRoot).keys, pr, pin)?.gate_dispositions;
|
||||
const gates = gateAcceptance({ cwd: ctx.repoRoot, branch: info.headRefName, pin, body: info.body ?? '', receipt: receipt.receipt, accepted, noted });
|
||||
return { lines: [...lines, ...gates.lines], ...(gates.failure ? { failure: gates.failure } : {}) };
|
||||
}
|
||||
|
||||
@@ -64,6 +66,7 @@ export function verifyPin(ctx: QueueContext, o: { pr: string; pin: string; accep
|
||||
if (info.state !== 'OPEN') return fail(lines, { code: 'QUEUE_NOT_READY', message: `#${o.pr} is ${info.state}` });
|
||||
if (info.headRefOid !== o.pin) return fail(lines, { code: 'QUEUE_LAND_PIN_MOVED', message: `#${o.pr}'s head is ${info.headRefOid.slice(0, 12)}, not the pin ${o.pin.slice(0, 12)}` });
|
||||
if (!havePin(root, o.pr, o.pin, info.headRefName)) return fail(lines, { code: 'QUEUE_NOT_READY', message: `cannot fetch the pin ${o.pin.slice(0, 12)} from ${info.headRefName} or refs/pull/${o.pr}/head`, fix: 'fix the fetch, then rerun verify' });
|
||||
rebuildFromNotes(root, ctx.remote ?? 'origin');
|
||||
const accepted = pinAcceptance(ctx, info, o.pr, o.pin, o.acceptGateDispositions);
|
||||
lines.push(...accepted.lines);
|
||||
if (accepted.failure) return fail(lines, accepted.failure);
|
||||
|
||||
+8
-6
@@ -294,11 +294,12 @@ export function refreshBase(ctx: QueueContext): QueueFailure | null {
|
||||
|
||||
/**
|
||||
* TRIAL_MERGES (rule 14): each open PR into the base that changes a path this PR changes, trial-merged with this head by git
|
||||
* merge-tree; one line per such PR, or a MISSING line when gh or the fetch cannot tell.
|
||||
* merge-tree; one line per such PR, or a MISSING line when gh or the fetch cannot tell. A PR from a fork is an outside
|
||||
* contribution, not a sibling lane: it is labelled and never fetched or merged (outside code is read as text only).
|
||||
*/
|
||||
export function trialMergeLines(ctx: QueueContext, pr: string, head: string, changed: readonly string[]): string[] {
|
||||
const list = ctx.gh(['pr', 'list', '--state', 'open', '--base', ctx.base, '--limit', '200', '--json', 'number,headRefOid,files']);
|
||||
let open: Array<{ number: number; headRefOid: string; files?: Array<{ path: string }> }> | undefined;
|
||||
const list = ctx.gh(['pr', 'list', '--state', 'open', '--base', ctx.base, '--limit', '200', '--json', 'number,headRefOid,files,isCrossRepository']);
|
||||
let open: Array<{ number: number; headRefOid: string; files?: Array<{ path: string }>; isCrossRepository?: boolean }> | undefined;
|
||||
try { open = list.ok ? JSON.parse(list.out) : undefined; } catch { open = undefined; }
|
||||
if (!Array.isArray(open)) return [`TRIAL_MERGES: MISSING: cannot list the open PRs into ${ctx.base} through gh (${(list.err ?? list.out).trim().split('\n')[0]?.slice(0, 160) || 'no JSON'}), so no trial merge ran (rule 14)`];
|
||||
const own = new Set(changed);
|
||||
@@ -308,6 +309,7 @@ export function trialMergeLines(ctx: QueueContext, pr: string, head: string, cha
|
||||
const remote = ctx.remote ?? 'origin';
|
||||
return siblings.map(p => {
|
||||
const at = `#${p.number} ${p.headRefOid.slice(0, 12)} shares ${p.shared.slice(0, 5).join(', ')}${p.shared.length > 5 ? ` (+${p.shared.length - 5} more)` : ''}`;
|
||||
if (p.isCrossRepository) return `TRIAL_MERGES: ${at}: outside PR from a fork, not a sibling lane; not trial-merged (rule 19)`;
|
||||
if (!git(ctx.repoRoot, ['cat-file', '-e', `${p.headRefOid}^{commit}`]).ok) git(ctx.repoRoot, ['fetch', '--no-tags', '-q', remote, `refs/pull/${p.number}/head`]);
|
||||
if (!git(ctx.repoRoot, ['cat-file', '-e', `${p.headRefOid}^{commit}`]).ok) return `TRIAL_MERGES: ${at}: MISSING: its head is not in this clone after git fetch ${remote} refs/pull/${p.number}/head, so no trial merge ran`;
|
||||
const m = git(ctx.repoRoot, ['merge-tree', '--write-tree', '--name-only', '--no-messages', head, p.headRefOid]);
|
||||
@@ -318,13 +320,13 @@ export function trialMergeLines(ctx: QueueContext, pr: string, head: string, cha
|
||||
});
|
||||
}
|
||||
|
||||
/** The newest row of a decision trail (gstack-decision-trail) whose phase is trail-read: its row number and the reader it names. */
|
||||
/** The newest row of a decision trail (gstack-decision-trail) whose phase is trail-read: its row number, the reader it names and its result, the reader's flags. */
|
||||
export function trailReadRow(file: string | undefined): ReadyTail['trailRead'] {
|
||||
if (!file) return { missing: 'ready got no --trail <decisions.tsv>' };
|
||||
let text: string;
|
||||
try { text = fs.readFileSync(file, 'utf8'); } catch (e: any) { return { missing: `cannot read --trail ${file} (${e?.code ?? 'unreadable'})` }; }
|
||||
const rows = text.split('\n').slice(1).filter(Boolean).map(l => l.split('\t'));
|
||||
for (let i = rows.length - 1; i >= 0; i--) if (rows[i]![1]?.trim().toLowerCase() === 'trail-read' && rows[i]![2]?.trim()) return { row: i + 1, reader: rows[i]![2]!.trim() };
|
||||
for (let i = rows.length - 1; i >= 0; i--) if (rows[i]![1]?.trim().toLowerCase() === 'trail-read' && rows[i]![2]?.trim()) return { row: i + 1, reader: rows[i]![2]!.trim(), flags: rows[i]![5]?.trim() ?? '' };
|
||||
return { missing: `${file} has no trail-read row` };
|
||||
}
|
||||
|
||||
@@ -417,7 +419,7 @@ export function ready(ctx: QueueContext, o: { pr: string; pregate?: string; gate
|
||||
const repo = repoIdentity(ctx.repoRoot);
|
||||
const now = nowIso();
|
||||
const remote = ctx.remote ?? 'origin';
|
||||
const p = persist(ctx.repoRoot, [{ schema: 1, kind: 'ready', repo_key: repo.key, pr: o.pr, head, base_sha: baseSha, ready_at: now, screen: { choice: 'no-screen', policy: null, nonce: null, run: null, merge_sha: null }, updated_at: now, ...(plan.record ? { plan: plan.record } : {}) }], { remote });
|
||||
const p = persist(ctx.repoRoot, [{ schema: 1, kind: 'ready', repo_key: repo.key, pr: o.pr, head, base_sha: baseSha, ready_at: now, screen: { choice: 'no-screen', policy: null, nonce: null, run: null, merge_sha: null }, updated_at: now, ...(plan.record ? { plan: plan.record } : {}), ...(gates?.noteRows?.length ? { gate_dispositions: gates.noteRows } : {}) }], { remote });
|
||||
lines.push(`READY_RECEIPT: ${readyPath(repo.key, o.pr, head)} (${p.detail})`);
|
||||
if (!p.pushed) return fail({ ...readyNoteUnpushed(o.pr, head, remote, p.detail), fix: `fix the notes push to ${remote} (the READY_RECEIPT line ends with its error), then rerun gstack-ship-queue ready --pr ${o.pr} with the same flags` }, lines, run);
|
||||
}
|
||||
|
||||
+10
-7
@@ -230,12 +230,13 @@ export function receiptSummaryLine(r: ShipReceipt): string {
|
||||
export const riskClassReceipt = (r: ShipReceipt | undefined) => r?.review_depth?.class === 'gate' || !!r?.review_depth?.risk?.length;
|
||||
|
||||
/** What ready found for the READY tail: its TRIAL_MERGES lines and the decision trail's cross-family read, or why there is none. */
|
||||
export interface ReadyTail { trialMerges: string[]; trailRead: { row: number; reader: string } | { missing: string } }
|
||||
export interface ReadyTail { trialMerges: string[]; trailRead: { row: number; reader: string; flags?: string } | { missing: string } }
|
||||
|
||||
/**
|
||||
* The rest of the READY block (GSTA-258 E1: the ready output is the whole READY): the receipt's review loop, ready's trial
|
||||
* merges, and the Attention section, whose opening line follows the receipt's risk class and the trail's cross-family read
|
||||
* (docs/unattended.md): a risk-class PR with no trail-read row prints MISSING instead of a line to fill in.
|
||||
* (docs/unattended.md): a risk-class PR with no trail-read row prints MISSING instead of a line to fill in. Its flags line is the
|
||||
* trail-read row's result, and with no such row there is none: the lane lists its own audit's flags, never a template line.
|
||||
*/
|
||||
export function readyTailLines(r: ShipReceipt | undefined, t: ReadyTail = { trialMerges: [], trailRead: { missing: 'ready did not look for one' } }): string[] {
|
||||
const loop = parseReviewLoop(r?.review_loop);
|
||||
@@ -254,7 +255,7 @@ export function readyTailLines(r: ShipReceipt | undefined, t: ReadyTail = { tria
|
||||
...(t.trialMerges.length ? t.trialMerges : ['TRIAL_MERGES: MISSING: ready did not check the open PRs that share a file (rule 14)']),
|
||||
'Attention:',
|
||||
reviewer,
|
||||
'<flags against decision-trail row numbers, or No flags>',
|
||||
...((legacy || risk) && 'row' in t.trailRead ? [/^(none|no flags?)?\.?$/i.test(t.trailRead.flags?.trim() ?? '') ? `No flags (trail row ${t.trailRead.row})` : `Flags (trail row ${t.trailRead.row}): ${oneLine(t.trailRead.flags!)}`] : []),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -442,16 +443,18 @@ export const STACK_PARENT_WALK = 100;
|
||||
* that squash-merged (or merged) into the base after the receipt was written against the base (GST-1199). A commit with no
|
||||
* product change of its own (a test-first commit) is no parent, since any base trivially holds it, and neither is a commit
|
||||
* rangeBase already held: a parent that landed before the review is part of the reviewed base, so measuring from it drops
|
||||
* nothing and compares the wrong range (yc-software/qm#3457, GST-3315). Null when no
|
||||
* commit within STACK_PARENT_WALK qualifies or git cannot tell; a conflicted product path is never held.
|
||||
* nothing and compares the wrong range (yc-software/qm#3457, GST-3315). That last skip is for a reviewed range (the receipt check
|
||||
* and Step 11.5); `reviewedRange` false drops it, for land's commit message, whose range starts at a merge base the child's merge of
|
||||
* the base moved past its parent's squash. Null when no commit within STACK_PARENT_WALK qualifies or git cannot tell; a conflicted
|
||||
* product path is never held.
|
||||
*/
|
||||
export function landedStackParent(repoRoot: string, s: { rangeBase: string; reviewed: string; currentBase: string }, product: readonly string[]): string | null {
|
||||
export function landedStackParent(repoRoot: string, s: { rangeBase: string; reviewed: string; currentBase: string }, product: readonly string[], reviewedRange = true): string | null {
|
||||
const run = (args: string[]) => spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8', timeout: 120_000, maxBuffer: 64 * 1024 * 1024 });
|
||||
const commits = run(['rev-list', '--topo-order', `--max-count=${STACK_PARENT_WALK + 1}`, `${s.rangeBase}..${s.reviewed}`]);
|
||||
if (commits.status !== 0) return null;
|
||||
for (const commit of commits.stdout.split('\n').filter(c => c && c !== s.reviewed)) {
|
||||
if (run(['diff', '--quiet', s.rangeBase, commit, '--', ...product]).status !== 1) continue;
|
||||
if (heldBy(repoRoot, commit, s.currentBase, product) && !heldBy(repoRoot, commit, s.rangeBase, product)) return commit;
|
||||
if (heldBy(repoRoot, commit, s.currentBase, product) && !(reviewedRange && heldBy(repoRoot, commit, s.rangeBase, product))) return commit;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -33,11 +33,12 @@ export function openingLines(body: string): string {
|
||||
return out.map(wrap).join('\n\n');
|
||||
}
|
||||
|
||||
/** Every distinct trailer git's own parser finds on the non-merge commits in from..to, oldest first (the first spelling wins); null when git cannot read the range. */
|
||||
export function branchTrailers(root: string, from: string, to: string): string[] | null {
|
||||
const r = git(root, ['log', '--reverse', '--no-merges', '--format=%(trailers:only,unfold)', `${from}..${to}`]);
|
||||
/** Every distinct trailer git's own parser finds on the non-merge commits reachable from `to` and from none of `from`, oldest first (the first spelling wins); null when git cannot read the range. */
|
||||
export function branchTrailers(root: string, from: string | readonly string[], to: string): string[] | null {
|
||||
const range = [...[from].flat().map(f => `^${f}`), to];
|
||||
const r = git(root, ['log', '--reverse', '--no-merges', '--format=%(trailers:only,unfold)', ...range]);
|
||||
if (r.status !== 0) return null;
|
||||
const authors = git(root, ['log', '--reverse', '--no-merges', '--format=%an <%ae>', `${from}..${to}`]);
|
||||
const authors = git(root, ['log', '--reverse', '--no-merges', '--format=%an <%ae>', ...range]);
|
||||
if (authors.status !== 0) return null;
|
||||
const others = authors.stdout.split('\n').filter(Boolean).filter((a, _, all) => a !== all[0]).map(a => `Co-authored-by: ${a}`);
|
||||
const seen = new Map<string, string>();
|
||||
@@ -61,8 +62,8 @@ export function landMethod(root: string, policy: Pick<ShipPolicy, 'history' | 'l
|
||||
* Refuses (error) when git cannot read the branch's commits or the message holds a HIGH redaction finding.
|
||||
*/
|
||||
export function landMessage(root: string, o: { pr: string; title: string; prBody: string; mergeBase: string; pin: string; tip: string; policy: Pick<ShipPolicy, 'history' | 'land'>; override?: string; visibility?: RepoVisibility }): LandMessage | { error: string } {
|
||||
const parent = landedStackParent(root, { rangeBase: o.mergeBase, reviewed: o.pin, currentBase: o.tip }, ['.']);
|
||||
const trailers = branchTrailers(root, parent ?? o.mergeBase, o.pin);
|
||||
const parent = landedStackParent(root, { rangeBase: o.mergeBase, reviewed: o.pin, currentBase: o.tip }, ['.'], false);
|
||||
const trailers = branchTrailers(root, parent ? [o.mergeBase, parent] : o.mergeBase, o.pin);
|
||||
if (!o.title.trim()) return { error: `#${o.pr} has no title to use as the commit subject` };
|
||||
if (!trailers) return { error: `git cannot read #${o.pr}'s commits ${(parent ?? o.mergeBase).slice(0, 12)}..${o.pin.slice(0, 12)}` };
|
||||
const subject = `${o.title.trim()} (#${o.pr})`;
|
||||
|
||||
Reference in new issue
Block a user