代码测试
This commit is contained in:
@@ -218,55 +218,66 @@ class ReportGenerator:
|
||||
lines.append(f' - {message}')
|
||||
lines.append('')
|
||||
|
||||
# AI 审查结果(单独展示)
|
||||
# AI 审查结果(适配新格式:issues 列表)
|
||||
if 'ai' in scan_results:
|
||||
ai_result = scan_results['ai']
|
||||
lines.append('')
|
||||
lines.append('## 🤖 AI 代码审查')
|
||||
lines.append('')
|
||||
lines.append(ai_result.get('summary', '无 AI 审查结果'))
|
||||
|
||||
# 新格式:直接使用 summary
|
||||
if 'summary' in ai_result:
|
||||
# summary 可能是字符串或 dict
|
||||
summary = ai_result.get('summary', '')
|
||||
if isinstance(summary, dict):
|
||||
lines.append(f"发现 {summary.get('total', 0)} 个问题,"
|
||||
f"错误 {summary.get('error', 0)},"
|
||||
f"警告 {summary.get('warning', 0)},"
|
||||
f"提示 {summary.get('info', 0)}")
|
||||
else:
|
||||
lines.append(str(summary))
|
||||
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', {})
|
||||
# 新格式:issues 列表
|
||||
ai_issues = ai_result.get('issues', [])
|
||||
if ai_issues:
|
||||
# 按文件分组
|
||||
issues_by_file = {}
|
||||
for issue in ai_issues:
|
||||
file_name = issue.get('file', 'unknown')
|
||||
if file_name not in issues_by_file:
|
||||
issues_by_file[file_name] = []
|
||||
issues_by_file[file_name].append(issue)
|
||||
|
||||
for file_name, issues in issues_by_file.items():
|
||||
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('')
|
||||
for i, issue in enumerate(issues[:10], 1):
|
||||
severity = issue.get('severity', 'Info')
|
||||
severity_emoji = {
|
||||
'ERROR': '🔴',
|
||||
'WARNING': '🟡',
|
||||
'INFO': 'ℹ️'
|
||||
}.get(severity.upper(), '⚪')
|
||||
|
||||
# 问题
|
||||
issues = review_content.get('问题', [])
|
||||
if issues:
|
||||
lines.append('**⚠️ 需要改进:**')
|
||||
for issue in issues[:3]:
|
||||
lines.append(f'- {issue}')
|
||||
lines.append('')
|
||||
line_num = issue.get('line', 0)
|
||||
symbol = issue.get('symbol', '')
|
||||
message = issue.get('message', 'No message')
|
||||
code_context = issue.get('code_context', '')
|
||||
defect_reason = issue.get('defect_reason', '')
|
||||
|
||||
# 优化建议
|
||||
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(f'{i}. {severity_emoji} **{severity}** - 行 {line_num}')
|
||||
if symbol:
|
||||
lines.append(f' - 标识: `{symbol}`')
|
||||
lines.append(f' - 问题: {message}')
|
||||
if code_context:
|
||||
lines.append(' - 代码:')
|
||||
lines.append('```')
|
||||
lines.append(code_context)
|
||||
lines.append('```')
|
||||
if defect_reason:
|
||||
lines.append(f' - 原因: {defect_reason}')
|
||||
lines.append('')
|
||||
|
||||
# 添加报告链接或下一步操作
|
||||
|
||||
Reference in New Issue
Block a user