ci: report model review completion diagnostics

This commit is contained in:
YXC0915 committed 2026-12-01 23:47:44 +08:00
1 parent 2fe6053fcd
commit de0333effd
1 file changed
+19 -4
+19 -4
View File
@@ -17,6 +17,7 @@ const REVIEW_SECTIONS = {
implementation: "实现精简与重复逻辑",
};
const DECISIONS = { merge: "可以合并", changes: "修改后再审", verify: "待实测后再决定", decline: "暂不合并" };
const FINISH_REASONS = new Set(["stop", "length", "content-filter", "tool-calls", "error", "other", "unknown"]);
function required(name) {
const value = process.env[name]?.trim();
@@ -152,12 +153,14 @@ async function reviewDiffs(context, includeDesignGuidelines) {
const binary = required("PR_REVIEW_OPENCODE");
const apiKey = required("PR_REVIEW_LLM_KEY");
const directory = await mkdtemp(join(required("RUNNER_TEMP"), "pr-review-"));
const input = JSON.stringify(context);
console.log("Requesting review for " + context.diffs.length + " files (" + input.length + " characters)");
let output;
try {
const { stdout, status, error } = spawnSync(binary, ["run", "--pure", "--format", "json", "--agent", "pr-review",
"--model", "review-api/" + model], {
cwd: directory,
input: JSON.stringify(context),
input,
encoding: "utf8",
timeout: 180_000,
maxBuffer: 1024 * 1024,
@@ -193,10 +196,22 @@ async function reviewDiffs(context, includeDesignGuidelines) {
throw new Error("OpenCode did not return readable review events");
}
const finish = events.findLast((event) => event.type === "step_finish");
if (finish?.part?.reason !== "stop" || events.some((event) => event.type === "error" || event.type === "tool_use")) {
throw new Error("OpenCode did not return a complete text-only review");
const errors = events.filter((event) => event.type === "error");
const text = events.filter((event) => event.type === "text");
const toolCalls = events.filter((event) => event.type === "tool_use");
if (finish?.part?.reason !== "stop" || errors.length || toolCalls.length) {
const diagnostic = {
finish: FINISH_REASONS.has(finish?.part?.reason) ? finish.part.reason : finish ? "unrecognized" : "absent",
textParts: text.length,
toolCalls: toolCalls.length,
errors: errors.map(({ error }) => ({
kind: typeof error?.name === "string" && /^[a-zA-Z]{1,40}Error$/.test(error.name) ? error.name : "other",
status: Number.isInteger(error?.data?.statusCode) ? error.data.statusCode : undefined,
})),
};
throw new Error("OpenCode did not return a complete text-only review " + JSON.stringify(diagnostic));
}
const answer = events.filter((event) => event.type === "text").map((event) => event.part.text).join("\n");
const answer = text.map((event) => event.part.text).join("\n");
let decoded;
try {
const content = answer.trim().replace(/^```(?:json)?\s*\n([\s\S]*?)\n```$/i, "$1");