Migrate review automation to OpenCode
This commit is contained in:
1 parent
27db22cd78
commit
8aaecb4dc7
21 files changed
+2703
-713
No files matched your search
+42
-14
@@ -1,36 +1,52 @@
|
||||
import type { ReviewDecision, ReviewFinding, ReviewMode } from "../types.js";
|
||||
import { config } from "../config.js";
|
||||
import { formatReviewStateMarker, type ReviewDisposition } from "./policy.js";
|
||||
|
||||
export function formatReviewBody(decision: ReviewDecision, unpostedFindings: ReviewFinding[], mode: ReviewMode): string {
|
||||
export type CategorizedFinding = ReviewFinding & {
|
||||
category: "review" | "change";
|
||||
};
|
||||
|
||||
export function formatReviewBody(
|
||||
decision: ReviewDecision,
|
||||
unpostedFindings: CategorizedFinding[],
|
||||
mode: ReviewMode,
|
||||
disposition: ReviewDisposition
|
||||
): string {
|
||||
const lines = [
|
||||
formatReviewStateMarker(mode, disposition, decision.review.length, decision.change.length),
|
||||
`## Automated review`,
|
||||
"",
|
||||
`Mode: ${mode === "lenient" ? "lenient" : "strict"}`,
|
||||
"",
|
||||
decision.summary,
|
||||
`### Comment`,
|
||||
"",
|
||||
...(decision.shouldClosePullRequest
|
||||
? [`Close PR: yes`, "", `Close reason: ${decision.closeReason}`, ""]
|
||||
decision.comment,
|
||||
"",
|
||||
`### Result for maintainers`,
|
||||
"",
|
||||
decision.result.summary,
|
||||
"",
|
||||
...(decision.result.shouldClosePullRequest
|
||||
? [`Close PR: yes`, "", `Close reason: ${decision.result.closeReason}`, ""]
|
||||
: []),
|
||||
`Decision: ${decision.safeToMerge ? "safe to merge" : "changes requested"}`
|
||||
`Model decision: ${decision.result.canMerge && decision.change.length === 0 ? "safe to merge" : "do not merge"}`,
|
||||
`Applied review policy: ${config.reviewPolicy}`,
|
||||
`Final status: ${formatDisposition(disposition)}`,
|
||||
"",
|
||||
`Required changes: ${decision.change.length}`,
|
||||
`Review notes: ${decision.review.length}`
|
||||
];
|
||||
|
||||
if (mode === "strict" && !decision.safeToMerge && !decision.shouldClosePullRequest) {
|
||||
if (mode === "strict" && decision.change.length > 0 && !decision.result.shouldClosePullRequest) {
|
||||
lines.push("", "Need a narrower pass? Comment `/lenient-check` on this PR.");
|
||||
}
|
||||
|
||||
if (decision.fixTips.length > 0) {
|
||||
lines.push("", "While making changes, also double-check:");
|
||||
for (const tip of decision.fixTips) {
|
||||
lines.push(`- ${tip}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (unpostedFindings.length > 0) {
|
||||
lines.push("", "Findings that could not be attached inline:");
|
||||
for (const finding of unpostedFindings) {
|
||||
lines.push(
|
||||
"",
|
||||
`- ${finding.path}:${finding.line} [${finding.severity}] ${finding.title}`,
|
||||
`- ${finding.path}:${finding.line} [${finding.category}] ${finding.title}`,
|
||||
` ${finding.body}`
|
||||
);
|
||||
}
|
||||
@@ -38,3 +54,15 @@ export function formatReviewBody(decision: ReviewDecision, unpostedFindings: Rev
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function formatDisposition(disposition: ReviewDisposition): string {
|
||||
if (disposition.blocksMerge) {
|
||||
return "changes requested";
|
||||
}
|
||||
|
||||
if (disposition.requiresAdminApproval) {
|
||||
return "waiting for repository administrator approval";
|
||||
}
|
||||
|
||||
return "safe to merge";
|
||||
}
|
||||
Reference in new issue
Block a user