idk
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
import type { AggregatedReview, Finding, ReviewSeverity } from "./types.ts";
|
||||
|
||||
const SEVERITY_ORDER: ReviewSeverity[] = ["error", "warning", "nit"];
|
||||
|
||||
const SEVERITY_LABEL: Record<ReviewSeverity, string> = {
|
||||
error: "Errors",
|
||||
warning: "Warnings",
|
||||
nit: "Nits",
|
||||
};
|
||||
|
||||
const SEVERITY_EMOJI: Record<ReviewSeverity, string> = {
|
||||
error: "🔴",
|
||||
warning: "🟡",
|
||||
nit: "🔵",
|
||||
};
|
||||
|
||||
function renderGroup(severity: ReviewSeverity, findings: Finding[]): string {
|
||||
const items = findings.map(
|
||||
(f) => `**\`${f.filename}\`** line ${f.line}\n> ${f.comment}`,
|
||||
);
|
||||
return `### ${SEVERITY_EMOJI[severity]} ${SEVERITY_LABEL[severity]} (${findings.length})\n\n${items.join("\n\n")}`;
|
||||
}
|
||||
|
||||
export function formatReview(
|
||||
review: AggregatedReview,
|
||||
files: string[],
|
||||
model: string,
|
||||
): string {
|
||||
const parts: string[] = [];
|
||||
|
||||
parts.push(`## 🤖 shockbot review\n\n> Reviewed ${files.length} file${files.length === 1 ? "" : "s"} using \`${model}\``);
|
||||
|
||||
// Summary section — join per-chunk summaries
|
||||
const summaries = review.summaries.filter(Boolean);
|
||||
if (summaries.length > 0) {
|
||||
parts.push(`**Summary**\n\n${summaries.join("\n\n")}`);
|
||||
}
|
||||
|
||||
// Group findings by severity
|
||||
const grouped = new Map<ReviewSeverity, Finding[]>();
|
||||
for (const severity of SEVERITY_ORDER) grouped.set(severity, []);
|
||||
for (const finding of review.findings) {
|
||||
grouped.get(finding.severity)?.push(finding);
|
||||
}
|
||||
|
||||
const hasFindings = review.findings.length > 0;
|
||||
if (hasFindings) {
|
||||
for (const severity of SEVERITY_ORDER) {
|
||||
const group = grouped.get(severity)!;
|
||||
if (group.length > 0) parts.push(renderGroup(severity, group));
|
||||
}
|
||||
} else {
|
||||
parts.push("No issues found. ✅");
|
||||
}
|
||||
|
||||
const timestamp = new Date().toISOString();
|
||||
parts.push(`---\n\n<sub>shockbot · \`${model}\` · ${timestamp}</sub>`);
|
||||
|
||||
return parts.join("\n\n---\n\n");
|
||||
}
|
||||
Reference in New Issue
Block a user