Appearance
报告导出
Git Doctor 支持将诊断结果导出为多种格式的报告。
支持的格式
| 格式 | 说明 | 适用场景 |
|---|---|---|
| HTML | 可视化仪表盘 | 分享、演示、存档 |
| Markdown | 纯文本格式 | 文档、Wiki、PR |
| JSON | 结构化数据 | CI/CD、程序处理 |
| Text | 控制台格式 | 快速查看、日志 |
导出方式
VS Code 插件
- 运行完整诊断:
Git Doctor: 运行完整诊断 - 导出报告:
Git Doctor: 导出诊断报告 - 选择导出格式
- 选择保存位置
CLI 命令行
bash
# HTML 报告(可视化仪表盘)
git-doctor export -f html -o report.html
# Markdown 报告
git-doctor export -f markdown -o report.md
# JSON 报告(程序处理)
git-doctor export -f json -o report.json
# Text 报告(控制台格式)
git-doctor export -f text -o report.txt报告内容
所有格式的报告都包含以下内容:
1. 健康评分
- 总体评分(0-100)
- 各维度评分
2. 仓库概览
- 仓库名称
- 分支信息
- 提交总数
- 贡献者数量
3. 诊断结果
- 仓库体积分析
- 提交质量评估
- 分支健康状态
- 安全风险扫描
4. 问题列表
- 按优先级排序
- 包含问题描述
- 提供修复建议
5. 技术债务
- 热点文件列表
- TDI 指数
- 治理建议
HTML 报告
特点
- 📊 可视化图表
- 🎨 美观的界面
- 📱 响应式设计
- 🔍 交互式探索
预览
┌─────────────────────────────────────────────────────┐
│ Git Doctor 健康报告 │
│ 生成时间: 2024-12-08 10:30:00 │
├─────────────────────────────────────────────────────┤
│ │
│ 健康评分 │
│ ┌─────────────────────────────────────┐ │
│ │ 85 / 100 │ │
│ │ ████████████████████░░░░░ │ │
│ └─────────────────────────────────────┘ │
│ │
│ 维度分析 │
│ ┌──────────┬──────────┬──────────┬──────────┐ │
│ │ 体积 │ 提交 │ 分支 │ 安全 │ │
│ │ 90/100 │ 78/100 │ 85/100 │ 87/100 │ │
│ └──────────┴──────────┴──────────┴──────────┘ │
│ │
└─────────────────────────────────────────────────────┘Markdown 报告
特点
- 📝 纯文本格式
- 📋 易于复制粘贴
- 📚 适合文档系统
- 🔗 支持 GitHub/GitLab 渲染
示例
markdown
# Git Doctor 健康报告
**仓库**: my-project
**生成时间**: 2024-12-08 10:30:00
## 健康评分
| 维度 | 评分 | 状态 |
|------|------|------|
| 总体 | 85/100 | ✅ 良好 |
| 体积 | 90/100 | ✅ 优秀 |
| 提交 | 78/100 | ⚠️ 一般 |
| 分支 | 85/100 | ✅ 良好 |
| 安全 | 87/100 | ✅ 良好 |
## 问题列表
### 🔴 高优先级
1. **僵尸分支**: feature/old-feature
- 最后更新: 120 天前
- 建议: 删除或激活
### 🟡 中优先级
2. **提交消息不规范**: 22% 的提交不符合规范
- 建议: 安装 commit-msg hookJSON 报告
特点
- 🔧 程序化处理
- 📊 完整数据
- 🔄 CI/CD 集成
- 🛠️ 自定义分析
结构
json
{
"version": "1.0.0",
"timestamp": "2024-12-08T10:30:00Z",
"repository": {
"name": "my-project",
"branch": "main",
"commits": 256
},
"healthScore": {
"total": 85,
"size": 90,
"commits": 78,
"branches": 85,
"security": 87
},
"issues": [
{
"id": "branch-001",
"type": "stale-branch",
"severity": "warning",
"title": "僵尸分支",
"description": "feature/old-feature 已 120 天未更新",
"suggestion": "删除或激活"
}
],
"hotspots": [
{
"path": "src/core/parser.ts",
"tdi": 85.3,
"churnCount": 45,
"bugFixCount": 12
}
]
}CI/CD 使用示例
bash
# 提取健康评分
SCORE=$(git-doctor export -f json | jq '.healthScore.total')
# 检查是否达标
if [ "$SCORE" -lt 60 ]; then
echo "Health score too low: $SCORE"
exit 1
fi
# 统计问题数量
ISSUES=$(git-doctor export -f json | jq '.issues | length')
echo "Found $ISSUES issues"自动化报告
GitHub Actions
yaml
name: Health Report
on:
schedule:
- cron: '0 0 * * 1' # 每周一
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Generate Report
run: |
npm install -g git-doctor
git-doctor export -f html -o health-report.html
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: health-report
path: health-report.html定期报告邮件
bash
#!/bin/bash
# weekly-report.sh
cd /path/to/repo
git-doctor export -f html -o /tmp/report.html
# 发送邮件(需要配置 mailx)
echo "本周仓库健康报告" | mailx -a /tmp/report.html -s "Git Health Report" team@company.com最佳实践
1. 版本控制报告
将 JSON 报告提交到仓库,跟踪健康变化:
bash
git-doctor export -f json -o .health/report-$(date +%Y%m%d).json
git add .health/
git commit -m "chore: add health report"2. PR 评论
在 PR 中自动添加健康报告:
yaml
- name: Comment PR
uses: actions/github-script@v6
with:
script: |
const report = require('./health-report.json')
github.rest.issues.createComment({
issue_number: context.issue.number,
body: `## Health Score: ${report.healthScore.total}/100`
})3. 仪表盘集成
将 JSON 数据导入 Grafana 等监控系统,实现长期跟踪。