/** * HU-5247: after a kj review is published, ask the Codex GitHub App for the PR head when its last * review is of an earlier commit. Once per head, and never a reason to fail the publish. */ import { runCommand } from "../utils/process.js"; import { judgeFootprint, readComments } from "./codex-footprint.js"; const headMark = (head) => ``; /** @returns {Promise<{asked?: string, warning?: string}>} */ export async function askCodex({ projectDir, pr, info, run = runCommand }) { const sha = info.headRefOid.slice(0, 7); try { const comments = await readComments({ projectDir, pr, run }); const mark = headMark(info.headRefOid); if (judgeFootprint(comments, info.headRefOid).state !== "other-commit" || comments.some((c) => String(c.body).includes(mark))) return {}; const res = await run("gh", ["pr", "comment", String(pr), "--body", `@codex review\n\n${mark}`], { cwd: projectDir }); if (res.exitCode !== 0) throw new Error(res.stderr || res.stdout || "gh pr comment failed"); return { asked: sha }; } catch (err) { return { warning: `Codex was not asked to review ${sha}: ${err.message.replaceAll(/\s+/g, " ").trim()}` }; } }