This commit is contained in:
Dang Zerong
2026-03-10 17:22:07 +08:00
parent 8594cf4d77
commit 17306c6814
9 changed files with 769 additions and 62 deletions

View File

@@ -63,7 +63,13 @@ class ReportGenerator:
total_warnings = 0
for scanner_name, result in scan_results.items():
# AI 审查的 summary 是字符串,跳过统计
if scanner_name == 'ai':
continue
summary = result.get('summary', {})
if not isinstance(summary, dict):
continue
total_issues += summary.get('total', 0)
total_errors += summary.get('error', 0) + summary.get('high', 0)
total_warnings += summary.get('warning', 0) + summary.get('medium', 0)
@@ -101,8 +107,10 @@ class ReportGenerator:
}
# 保存报告文件
report_file = None
if self.keep_files:
self._save_report(report)
report_file = self._save_report(report)
report['report_file'] = report_file
return report
@@ -161,6 +169,10 @@ class ReportGenerator:
lines.append('')
for scanner_name, result in scan_results.items():
# 跳过 AI 审查结果(单独处理)
if scanner_name == 'ai':
continue
tool_name = result.get('tool', scanner_name)
summary = result.get('summary', {})
@@ -204,6 +216,57 @@ class ReportGenerator:
lines.append(f' - {message}')
lines.append('')
# AI 审查结果(单独展示)
if 'ai' in scan_results:
ai_result = scan_results['ai']
lines.append('')
lines.append('## 🤖 AI 代码审查')
lines.append('')
lines.append(ai_result.get('summary', '无 AI 审查结果'))
lines.append('')
reviews = ai_result.get('reviews', [])
if reviews:
for i, review in enumerate(reviews, 1):
file_name = review.get('file', 'unknown')
review_content = review.get('review', {})
lines.append(f'### 📄 {file_name}')
lines.append('')
# 优点
advantages = review_content.get('优点', [])
if advantages:
lines.append('**✅ 代码优点:**')
for adv in advantages[:3]:
lines.append(f'- {adv}')
lines.append('')
# 问题
issues = review_content.get('问题', [])
if issues:
lines.append('**⚠️ 需要改进:**')
for issue in issues[:3]:
lines.append(f'- {issue}')
lines.append('')
# 优化建议
optimizations = review_content.get('优化', [])
if optimizations:
lines.append('**💡 优化建议:**')
for opt in optimizations[:3]:
lines.append(f'- {opt}')
lines.append('')
# 原始回复(如果不是 JSON 格式)
raw = review_content.get('raw_review')
if raw:
lines.append('**📝 AI 原始回复:**')
lines.append('```')
lines.append(raw[:500] + '...' if len(raw) > 500 else raw)
lines.append('```')
lines.append('')
# 添加报告链接或下一步操作
lines.append('---')
lines.append('')
@@ -211,8 +274,13 @@ class ReportGenerator:
return '\n'.join(lines)
def _save_report(self, report: Dict[str, Any]):
"""保存报告到文件"""
def _save_report(self, report: Dict[str, Any]) -> str:
"""
保存报告到文件
Returns:
保存的文件路径
"""
try:
# 生成文件名
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
@@ -225,6 +293,8 @@ class ReportGenerator:
f.write(report['markdown'])
logger.info(f'报告已保存: {filepath}')
return filepath
# 同时保存 JSON 格式(便于程序解析)
json_filename = filename.replace('.md', '.json')