This commit is contained in:
Dang Zerong
2026-03-10 11:18:39 +08:00
parent 31e3b7b497
commit 8594cf4d77
4 changed files with 208 additions and 14 deletions

View File

@@ -37,7 +37,9 @@ class ReportGenerator:
commit_id: str,
commit_message: str,
author: str,
scan_results: Dict[str, Any]
scan_results: Dict[str, Any],
pr_url: str = None,
target_branch: str = None
) -> Dict[str, Any]:
"""
生成扫描报告
@@ -49,6 +51,8 @@ class ReportGenerator:
commit_message: 提交信息
author: 提交者
scan_results: 扫描结果
pr_url: PR 链接(可选)
target_branch: 目标分支(可选,用于 PR 扫描)
Returns:
报告数据
@@ -89,8 +93,10 @@ class ReportGenerator:
'total_errors': total_errors,
'total_warnings': total_warnings,
'scan_results': scan_results,
'pr_url': pr_url,
'target_branch': target_branch,
'markdown': self._generate_markdown(
repo_name, branch, commit_id, commit_message, author, scan_results, status, status_text
repo_name, branch, commit_id, commit_message, author, scan_results, status, status_text, pr_url, target_branch
)
}
@@ -109,13 +115,18 @@ class ReportGenerator:
author: str,
scan_results: Dict[str, Any],
status: str,
status_text: str
status_text: str,
pr_url: str = None,
target_branch: str = None
) -> str:
"""生成 Markdown 格式的报告"""
lines = []
# 标题
lines.append('# 📊 代码质量扫描报告')
# 标题 - 根据是否为 PR 扫描显示不同标题
if pr_url:
lines.append('# 📊 PR 代码质量扫描报告')
else:
lines.append('# 📊 代码质量扫描报告')
lines.append('')
# 基本信息
@@ -124,7 +135,15 @@ class ReportGenerator:
lines.append(f'| 项目 | 内容 |')
lines.append(f'|------|------|')
lines.append(f'| 仓库 | `{repo_name}` |')
lines.append(f'| 分支 | `{branch}` |')
# 如果是 PR显示 PR 特有信息
if pr_url and target_branch:
lines.append(f'| 源分支 | `{branch}` |')
lines.append(f'| 目标分支 | `{target_branch}` |')
lines.append(f'| PR 链接 | [查看 PR]({pr_url}) |')
else:
lines.append(f'| 分支 | `{branch}` |')
lines.append(f'| 提交 | `{commit_id}` |')
lines.append(f'| 提交者 | {author} |')
lines.append(f'| 提交信息 | {commit_message[:50]}... |' if len(commit_message) > 50 else f'| 提交信息 | {commit_message} |')