ci: keep PR reviews focused on code findings

This commit is contained in:
Nwflower committed 2026-12-03 04:50:41 -07:00
1 parent 5e9621b7dd
commit 164ea7f7ba
4 files changed
+21 -154

No files matched your search

-44
View File
@@ -16,33 +16,11 @@ export const english = {
coverageComplete: "Complete for the selected scope",
findings: "Reported defects",
withheld: "Candidates missing required evidence fields",
evidenceIncomplete: "Some candidates lack the evidence needed to assess them.",
questions: "Decisions needed before merging",
clarify: "Clarify the expected behavior",
clarifyReason: "Resolve the contract questions above before merging.",
warnings: "Incomplete review tasks",
tests: "CI for this PR commit",
ciRun: "CI run",
ciPassed: "Passed",
ciFailed: "Failed",
ciNoPass: "No passing result",
ciActionRequired: "CI needs manual action.",
ciPending: "Pending",
ciMissing: "No CI run found for this commit.",
recommendation: "Merge recommendation",
merge: "Ready to merge",
changes: "Revise and review again",
inspect: "Review the remaining changes",
awaitCI: "No code blockers found. Awaiting CI.",
conflict: "GitHub detected merge conflicts. Resolve them and request another review.",
mainMoved: "The default branch moved during this review.",
ciRequired: "This commit has no passing CI result yet.",
fixCI: "Resolve the CI failure before merging.",
fixFindings: "Address the actionable findings below before merging.",
incomplete: "Some changes or review tasks were not covered; complete the review before merging.",
inline: "Inline findings",
unanchored: "Findings without a stable inline diff anchor",
noFindings: "No actionable issues found in the reviewed changes.",
noDiff: "No reviewable text changes remained after generated and lock files were excluded.",
inlineFallback: "GitHub could not attach inline comments. See the findings below.",
};
@@ -65,33 +43,11 @@ export const chinese = {
coverageComplete: "已完成所选范围",
findings: "已报告缺陷",
withheld: "缺少必需证据字段的候选意见",
evidenceIncomplete: "部分候选意见缺少必要证据,需要人工核对。",
questions: "合并前需确认的问题",
clarify: "确认预期行为",
clarifyReason: "合并前确认上方列出的行为约定。",
warnings: "未完成的审查任务",
tests: "当前 PR 提交的 CI",
ciRun: "CI 运行记录",
ciPassed: "通过",
ciFailed: "失败",
ciNoPass: "无通过结果",
ciActionRequired: "CI 需要人工处理。",
ciPending: "尚未完成",
ciMissing: "未找到对应提交的 CI 记录。",
recommendation: "合并建议",
merge: "可以合并",
changes: "修改后再审",
inspect: "先审完剩余改动",
awaitCI: "代码未见阻塞,等待 CI",
conflict: "GitHub 检测到合并冲突,解决后重新审核。",
mainMoved: "审核期间主线有更新。",
ciRequired: "当前提交还没有 CI 通过记录。",
fixCI: "合并前处理 CI 失败项。",
fixFindings: "合并前处理下方有证据的实质问题。",
incomplete: "部分改动或审查任务未覆盖,合并前补齐审查。",
inline: "行内问题",
unanchored: "无法稳定定位到差异行的有效问题",
noFindings: "已审核的差异中未发现可报告的问题。",
noDiff: "排除生成文件与锁文件后,没有可审核的文本改动。",
inlineFallback: "GitHub 未能附加行内评论,审核意见如下。",
};
+3 -68
View File
@@ -429,25 +429,6 @@ async function listChangedFiles(github, path) {
return files.slice(0, MAX_FILES);
}
export async function waitForCI(github, repoPath, pull, number, { wait = false } = {}) {
if (wait) throw new Error("CI polling is disabled for PR review");
if (pull.base.ref !== pull.base.repo.default_branch || !pull.head.repo) return { status: "unavailable" };
const path = repoPath + "/actions/workflows/ci.yml/runs?event=pull_request&per_page=20&head_sha=" + pull.head.sha;
const { data } = await github(path);
const run = data.workflow_runs.find((run) => run.head_sha === pull.head.sha
&& run.head_repository?.full_name === pull.head.repo.full_name && run.head_branch === pull.head.ref
&& (!run.pull_requests.length || run.pull_requests.some((pr) => pr.number === Number(number))));
if (run?.status !== "completed") return { status: run?.status ?? "unavailable", id: run?.id, attempt: run?.run_attempt, url: run?.html_url };
const { data: jobs } = await github(repoPath + "/actions/runs/" + run.id + "/attempts/" + run.run_attempt + "/jobs");
const verify = jobs.jobs.find((job) => job.name === "verify");
const steps = verify?.steps.filter((step) => /^(CI tests|Frontend test|Go test|Bundle frontend|Build reims-go|WebView2)/.test(step.name));
return {
status: "completed", id: run.id, attempt: run.run_attempt, url: run.html_url,
conclusion: verify?.conclusion ?? run.conclusion,
steps: (steps ?? []).map(({ name, conclusion }) => ({ name, conclusion })),
};
}
async function mainlineContext(github, repoPath, pull, files) {
const branch = pull.base.repo.default_branch;
const refPath = repoPath + "/git/ref/heads/" + encodeURIComponent(branch);
@@ -477,21 +458,12 @@ async function mainlineContext(github, repoPath, pull, files) {
};
}
export function reviewSummary(copy, assessment, ci, { incomplete, mergeable, total = 0, withheld = 0, questions = [], fallback = [] }) {
export function reviewSummary(copy, assessment, { incomplete, total = 0, withheld = 0, questions = [], fallback = [] }) {
const lines = [];
lines.push("- **" + copy.coverage + "** " + (incomplete ? copy.coveragePartial : copy.coverageComplete));
lines.push("- **" + copy.findings + "** " + total);
if (withheld) lines.push("- **" + copy.withheld + "** " + withheld);
if (assessment.warnings?.length) lines.push("- **" + copy.warnings + "** " + assessment.warnings.length);
const ciPassed = ci.status === "completed" && ci.conclusion === "success";
const ciFailed = ci.status === "completed" && ["failure", "timed_out"].includes(ci.conclusion);
const ciNeedsAction = ci.conclusion === "action_required" || ci.status === "action_required";
let ciStatus = ci.id ? copy.ciPending : copy.ciMissing;
if (ciNeedsAction) ciStatus = copy.ciActionRequired;
else if (ciPassed) ciStatus = copy.ciPassed;
else if (ci.status === "completed") ciStatus = (ciFailed ? copy.ciFailed : copy.ciNoPass) + " (`" + ci.conclusion + "`)";
lines.push("\n**" + copy.tests + "** " + ciStatus + (ci.url ? " · [" + copy.ciRun + "](" + ci.url + ")" : ""));
for (const step of ci.steps ?? []) lines.push("- " + plainMarkdown(step.name) + " · " + plainMarkdown(step.conclusion ?? "—"));
if (fallback.length) {
lines.push("\n**" + copy.unanchored + "**");
for (const finding of fallback) lines.push(summaryFinding(finding));
@@ -500,31 +472,6 @@ export function reviewSummary(copy, assessment, ci, { incomplete, mergeable, tot
lines.push("\n**" + copy.questions + "**");
for (const question of questions) lines.push("- " + plainMarkdown(shortText(question, 500)));
}
let decision = "merge";
let reason = copy.noFindings;
if (mergeable === false) {
decision = "changes";
reason = copy.conflict;
} else if (ciFailed) {
decision = "changes";
reason = copy.fixCI;
} else if (total > 0) {
decision = "changes";
reason = copy.fixFindings;
} else if (incomplete) {
decision = "inspect";
reason = copy.incomplete;
} else if (withheld) {
decision = "inspect";
reason = copy.evidenceIncomplete;
} else if (questions.length) {
decision = "clarify";
reason = copy.clarifyReason;
} else if (!ciPassed) {
decision = "awaitCI";
reason = copy.ciRequired;
}
lines.push("\n**" + copy.recommendation + " · " + copy[decision] + "** " + reason);
return lines.join("\n");
}
@@ -801,18 +748,6 @@ export async function run() {
return current.state === "open" && snapshot(current).join(":") === revision ? current : null;
}
if (!(await currentPR())) {
console.log("PR changed while the review was running");
return;
}
let ci;
try {
ci = await waitForCI(github, repoPath, pull, number, { wait: false });
} catch (error) {
console.warn("Could not read current CI status: " + error.message);
ci = { status: "unavailable" };
}
const latestPR = await currentPR();
if (!latestPR) {
console.log("PR changed before the review could be published");
return;
}
@@ -834,8 +769,8 @@ export async function run() {
const incremental = range.incremental ? "\n\n" + copy.incremental + " `" + range.lastHeadSha.slice(0, 12) + "`" : "";
const incomplete = assessment.status === "partial" || assessment.status === "completed_with_errors"
|| assessment.warnings.length > 0 || (assessment.status === "skipped" && stats.files > 0);
const summaryBody = reviewSummary(copy, assessment, ci, {
incomplete, mergeable: latestPR.mergeable, total, withheld, questions, fallback,
const summaryBody = reviewSummary(copy, assessment, {
incomplete, total, withheld, questions, fallback,
});
const publishedMarker = reviewMarker(pull, mainline.sha, incomplete);
const summary = publishedMarker + "\n## " + copy.heading + "\n\n" + copy.mainline + " `" + mainline.sha.slice(0, 12) + "` · " + coverage
+16 -40
View File
@@ -22,7 +22,6 @@ import {
reviewWithOCR,
selectReviewRange,
shouldSkipAutoReview,
waitForCI,
} from "./pr-review.mjs";
const A = "a".repeat(40);
@@ -216,8 +215,8 @@ test("finding filtering sorts severity and renders plain single-line and multi-l
assert.doesNotMatch(result.comments[1].body, /suggestion|keepOldConfig/);
assert.equal(result.fallback.length, 1);
assert.equal(result.total, 3);
assert.match(reviewSummary(chinese, { comments: [], warnings: [] }, { status: "completed", conclusion: "success" }, {
incomplete: false, mergeable: true, total: 3, fallback: result.fallback,
assert.match(reviewSummary(chinese, { comments: [], warnings: [] }, {
incomplete: false, total: 3, fallback: result.fallback,
}), /无法稳定定位到差异行的有效问题[\s\S]*99.*backup is rejected/);
});
@@ -232,7 +231,7 @@ test("public reviews retain prose around model code blocks and require opt-in fo
assert.doesNotMatch(comment.body, /callMissingMethod|cancelTask|```/);
const [suggestion] = classifyFindings(input, locations, { publishSuggestions: true }).comments;
assert.match(suggestion.body, /```suggestion\ncancelTask\(id\)\n```/);
const summary = reviewSummary(english, { message: "One issue found.\n~~~js\nignoreThis()\n~~~" }, {}, {});
const summary = reviewSummary(english, { message: "One issue found.\n~~~js\nignoreThis()\n~~~" }, {});
assert.match(summary, /Reported defects.*0/);
assert.doesNotMatch(summary, /One issue found/);
assert.doesNotMatch(summary, /ignoreThis/);
@@ -266,50 +265,27 @@ test("publication requires evidence and keeps merge-relevant contract questions
assert.equal(result.withheld, 3);
assert.equal(result.questions.length, 1);
assert.ok(result.comments.every(({ body }) => !/Trigger:|Impact:|Evidence:/.test(body)));
const summary = reviewSummary(english, { warnings: [{}], message: "8 findings" }, { status: "completed", conclusion: "success" }, { ...result, incomplete: true });
const summary = reviewSummary(english, { warnings: [{}], message: "8 findings" }, { ...result, incomplete: true });
assert.match(summary, /Review coverage.*Incomplete/);
assert.match(summary, /Reported defects.*3/);
assert.match(summary, /Decisions needed before merging[\s\S]*Should an open dialog close/);
assert.doesNotMatch(summary, /8 findings/);
const questionOnly = reviewSummary(english, {}, { status: "completed", conclusion: "success" }, { incomplete: false, questions: result.questions });
assert.match(questionOnly, /Clarify the expected behavior/);
const withheldOnly = reviewSummary(english, {}, { status: "completed", conclusion: "success" }, { withheld: 3 });
assert.match(withheldOnly, /Some candidates lack the evidence/);
const questionOnly = reviewSummary(english, {}, { incomplete: false, questions: result.questions });
assert.match(questionOnly, /Decisions needed before merging/);
const withheldOnly = reviewSummary(english, {}, { withheld: 3 });
assert.match(withheldOnly, /Candidates missing required evidence fields.*3/);
assert.doesNotMatch(withheldOnly, /Ready to merge/);
});
const pull = {
base: { ref: "main", repo: { default_branch: "main" } },
head: { sha: B, ref: "feature", repo: { full_name: "fork/Reims-Go" } },
};
const run = { id: 100, run_attempt: 2, head_sha: B, head_branch: "feature", head_repository: pull.head.repo, pull_requests: [] };
test("CI publication lookup is a single non-blocking request and preserves step summaries", async () => {
let calls = 0;
const queued = await waitForCI(async () => {
calls++;
return { data: { workflow_runs: [{ ...run, status: "queued" }] } };
}, "/repos/test/Reims-Go", pull, 42, { wait: false });
assert.equal(queued.status, "queued");
assert.equal(calls, 1);
const passed = await waitForCI(async (route) => route.endsWith("/100/attempts/2/jobs")
? { data: { jobs: [{ name: "verify", conclusion: "success", steps: [{ name: "Go test", conclusion: "success" }] }] } }
: { data: { workflow_runs: [{ ...run, status: "completed", conclusion: "success", html_url: "https://github.com/test/run/100" }] } },
"/repos/test/Reims-Go", pull, 42, { wait: false });
const summary = reviewSummary(english, { message: "No issues", comments: [], warnings: [] }, passed, { incomplete: false, mergeable: true, hasFindings: false });
assert.match(summary, /Go test · success/);
assert.match(summary, /Ready to merge/);
const waiting = reviewSummary(chinese, { comments: [], warnings: [] }, queued, { incomplete: false, mergeable: true, hasFindings: false });
assert.match(waiting, /代码未见阻塞,等待 CI/);
});
test("CI failures and incomplete OCR results affect the final recommendation independently", () => {
const failed = reviewSummary(chinese, { comments: [], warnings: [] }, { status: "completed", conclusion: "failure" }, { incomplete: false, mergeable: true, hasFindings: false });
assert.match(failed, /修改后再审/);
assert.match(failed, /处理 CI 失败项/);
const partial = reviewSummary(chinese, { comments: [], warnings: [{}] }, { status: "completed", conclusion: "success" }, { incomplete: true, mergeable: true, hasFindings: false });
assert.match(partial, /先审完剩余改动/);
test("a code-only review reports coverage and defects without restating GitHub checks", () => {
const complete = reviewSummary(english, { warnings: [] }, { incomplete: false });
assert.match(complete, /Review coverage.*Complete for the selected scope/);
assert.match(complete, /Reported defects.*0/);
assert.doesNotMatch(complete, /CI|merge/i);
const partial = reviewSummary(chinese, { warnings: [{}] }, { incomplete: true });
assert.match(partial, /审查覆盖.*部分完成/);
assert.match(partial, /未完成的审查任务/);
assert.doesNotMatch(partial, /CI|合并建议/);
});
async function fakeOCR(t, { exitCode = 0, stdout = null } = {}) {