Harden post-merge review: record filing before the create call, never re-file for a PR with a follow-up, scope diffs to the PR, dedupe, clean public text

This commit is contained in:
aiongg committed 2026-11-03 23:29:52 +00:00
1 parent aadb0fdd0e
commit 16da4f2701
20 files changed
+675 -123

No files matched your search

+23 -4
View File
@@ -182,12 +182,31 @@ export function ghFork(w: Writer, exec: Exec, repo: string, details: Details = {
return viaGh(w, exec, "fork-create", repo, details, ["repo", "fork", `${ORG}/${repo}`, "--clone=false"]);
}
/** Opens an issue; returns its number and URL. Throws when `gh` fails or prints no issue URL. `target` is the item the issue follows up. */
/** `clear`: GitHub refused the request, so no issue can exist. Otherwise the outcome is unknown (a timeout, a lost response, a success without a URL). */
export class IssueError extends Error {
clear: boolean;
constructor(message: string, clear: boolean) { super(message); this.clear = clear; }
}
// gh's own wording when GitHub rejects the request before creating anything.
const REFUSED = /issues are disabled|has disabled issues|could not resolve to a repository|not found|forbidden|must have (?:admin|write|push)|permission|requires authentication|bad credentials|gh auth login|HTTP (?:401|403|404|410|422)|validation failed/i;
/**
* Opens an issue; returns its number and URL. Throws an IssueError when `gh` fails or prints no issue URL; `clear` tells
* whether the failure certainly left no issue behind. `target` is the item the issue follows up.
*/
export async function createIssue(w: Writer, exec: Exec, o: { repo: string; target: string; title: string; body: string }, details: Details = {}): Promise<{ number: number; url: string }> {
const r = await viaGh(w, exec, "postmerge-file", o.target, { ...details, title: o.title, text: o.body },
["issue", "create", "--repo", `${ORG}/${o.repo}`, "--title", o.title, "--body-file", "-"], o.body);
let r: ExecResult;
try {
r = await viaGh(w, exec, "postmerge-file", o.target, { ...details, title: o.title, text: o.body },
["issue", "create", "--repo", `${ORG}/${o.repo}`, "--title", o.title, "--body-file", "-"], o.body);
} catch (e) {
// exec rejects only when the command could not be started.
throw new IssueError(oneLine(String((e as Error).message ?? e)), true);
}
const url = r.stdout.match(/https:\/\/github\.com\/\S+\/issues\/(\d+)/);
if (r.code !== 0 || !url) throw new Error(oneLine(r.stderr || r.stdout) || `exit code ${r.code}`);
if (r.code !== 0) { const m = oneLine(r.stderr || r.stdout) || `exit code ${r.code}`; throw new IssueError(m, REFUSED.test(m)); }
if (!url) throw new IssueError(oneLine(r.stderr || r.stdout) || "gh printed no issue URL", false);
return { number: Number(url[1]), url: url[0] };
}