Repository navigation
Expand file tree
/
Copy pathreport.py
More file actions
85 lines (75 loc) · 2.45 KB
/
Copy pathreport.py
File metadata and controls
85 lines (75 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import annotations
import json
from datetime import datetime
from models import ReviewReport, Issue
SEVERITY_EMOJI = {
"CRITICAL": "🔴",
"HIGH": "🟠",
"MEDIUM": "🟡",
"LOW": "🔵",
"INFO": "⚪",
}
CATEGORY_LABEL = {
"bug": "Bug",
"security": "Security",
"performance": "Performance",
"style": "Style",
"improvement": "Improvement",
}
def _score_badge(score: int) -> str:
if score >= 70:
label = "Good"
elif score >= 40:
label = "Fair"
else:
label = "Needs Work"
return f"{score}/100 ({label})"
def to_markdown(report: ReviewReport, language: str = "", title: str = "Code Review Report") -> str:
lines: list[str] = [
f"# {title}",
f"_Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}_",
"",
"## Summary",
"",
f"> {report.summary}",
"",
f"**Quality Score:** {_score_badge(report.overall_score)}",
"",
"| Metric | Count |",
"|--------|-------|",
f"| Total Issues | {report.total_issues} |",
f"| Critical | {report.critical_count} |",
f"| High | {report.high_count} |",
f"| Medium | {sum(1 for i in report.issues if i.severity == 'MEDIUM')} |",
f"| Low | {sum(1 for i in report.issues if i.severity == 'LOW')} |",
f"| Info | {sum(1 for i in report.issues if i.severity == 'INFO')} |",
"",
"---",
"",
"## Issues",
"",
]
if not report.issues:
lines.append("_No confirmed issues found._\n")
else:
for iss in report.issues:
emoji = SEVERITY_EMOJI.get(iss.severity, "")
cat = CATEGORY_LABEL.get(iss.category, iss.category.title())
line_ref = f" (line {iss.line_number})" if iss.line_number else ""
lines += [
f"### {emoji} [{iss.severity}] {iss.description[:80]}",
"",
f"- **Category:** {cat}",
f"- **Location:** {line_ref.strip() or 'N/A'}",
f"- **Confidence:** {iss.confidence.title()}",
"",
f"**Description:** {iss.description}",
"",
f"**Suggestion:** {iss.suggestion}" if iss.suggestion else "",
"",
"---",
"",
]
return "\n".join(lines)
def to_json(report: ReviewReport) -> str:
return report.model_dump_json(indent=2)