commit-analysis
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommit Analysis & Regression Detection
提交分析与回归检测
Overview
概述
Automated tools for detecting regressions and analyzing code changes:
| Tool | Purpose | Speed |
|---|---|---|
| scripts/smart_commit_analyzer.py | Auto-evolving regression detection | Fast |
| scripts/analyze_commits_ai.py | AI semantic analysis (DeepSeek) | Slow |
| scripts/analyze_git_changes.py | Git history statistics | Fast |
| scripts/validate_commit_fixes.py | Legacy manual rules (deprecated) | Fast |
用于检测回归问题和分析代码变更的自动化工具:
| 工具 | 用途 | 速度 |
|---|---|---|
| scripts/smart_commit_analyzer.py | 可自动演进的回归检测 | 快速 |
| scripts/analyze_commits_ai.py | AI语义分析(基于DeepSeek) | 缓慢 |
| scripts/analyze_git_changes.py | Git历史统计分析 | 快速 |
| scripts/validate_commit_fixes.py | 传统手动规则(已废弃) | 快速 |
Recommended Tool: smart_commit_analyzer.py
推荐工具:smart_commit_analyzer.py
This is the primary regression detection tool. Rules are automatically generated from git history.
这是核心回归检测工具,规则会从Git历史中自动生成。
Commands
命令
bash
undefinedbash
undefinedFull analysis (update rules + validate)
完整分析(更新规则 + 验证)
python3 scripts/smart_commit_analyzer.py
python3 scripts/smart_commit_analyzer.py
Update rules only (scan git for new fixes)
仅更新规则(扫描Git获取新修复记录)
python3 scripts/smart_commit_analyzer.py --update
python3 scripts/smart_commit_analyzer.py --update
Validate only (check existing rules)
仅验证(检查现有规则)
python3 scripts/smart_commit_analyzer.py --validate
python3 scripts/smart_commit_analyzer.py --validate
Show all rules
查看所有规则
python3 scripts/smart_commit_analyzer.py --show-rules
python3 scripts/smart_commit_analyzer.py --show-rules
JSON output (for CI/CD)
JSON格式输出(用于CI/CD)
python3 scripts/smart_commit_analyzer.py --json
undefinedpython3 scripts/smart_commit_analyzer.py --json
undefinedExpected Output
预期输出
🔍 Smart Commit Analyzer
============================================================
Step 1: 从 Git 历史更新规则库...
📊 扫描到 78 个修复提交
✅ 新增 5 条规则
Step 2: 验证所有规则...
============================================================
📋 验证结果
============================================================
✅ 通过: 70
❌ 失败: 2
⚠️ 警告: 3
⏭️ 跳过: 0🔍 Smart Commit Analyzer
============================================================
Step 1: 从Git历史更新规则库...
📊 扫描到78个修复提交
✅ 新增5条规则
Step 2: 验证所有规则...
============================================================
📋 验证结果
============================================================
✅ 通过: 70
❌ 失败: 2
⚠️ 警告: 3
⏭️ 跳过: 0How It Works
工作原理
┌─────────────────────────────────────────────────────────┐
│ Step 1: git log --grep="fix" │
│ → Auto-discover all fix commits │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 2: git show <commit> -- <file> │
│ → Extract key code patterns from diffs │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 3: Save to configs/auto_generated_rules.json │
│ → Rules auto-grow with new fix commits │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 4: Validate all rules │
│ → Detect regressions (missing patterns) │
└─────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────┐
│ Step 1: git log --grep="fix" │
│ → 自动发现所有修复提交 │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 2: git show <commit> -- <file> │
│ → 从代码差异中提取关键代码模式 │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 3: Save to configs/auto_generated_rules.json │
│ → 规则会随新修复提交自动增长 │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ Step 4: Validate all rules │
│ → 检测回归问题(缺失的代码模式) │
└─────────────────────────────────────────────────────────┘AI Deep Analysis (Optional)
AI深度分析(可选)
Requires environment variable.
DEEPSEEK_API_KEYbash
undefined需要配置环境变量。
DEEPSEEK_API_KEYbash
undefinedAnalyze last 10 commits with AI
使用AI分析最近10次提交
python3 scripts/analyze_commits_ai.py --commits 10
python3 scripts/analyze_commits_ai.py --commits 10
JSON output
JSON格式输出
python3 scripts/analyze_commits_ai.py --commits 10 --json
undefinedpython3 scripts/analyze_commits_ai.py --commits 10 --json
undefinedGit History Analysis
Git历史分析
bash
undefinedbash
undefinedAnalyze last 50 commits
分析最近50次提交
python3 scripts/analyze_git_changes.py
python3 scripts/analyze_git_changes.py
Show only fix commits
仅显示修复提交
python3 scripts/analyze_git_changes.py --fix-only
python3 scripts/analyze_git_changes.py --fix-only
Analyze more commits
分析更多提交
python3 scripts/analyze_git_changes.py --commits 100
undefinedpython3 scripts/analyze_git_changes.py --commits 100
undefinedGitHub Actions Integration
GitHub Actions集成
These tools run automatically on every push/PR via :
.github/workflows/commit-analysis.yml| Job | Tool | Trigger |
|---|---|---|
| Smart Regression Detection | scripts/smart_commit_analyzer.py | Always |
| AI Deep Analysis | scripts/analyze_commits_ai.py | If DEEPSEEK_API_KEY set |
这些工具会通过在每次推送/PR时自动运行:
.github/workflows/commit-analysis.yml| 任务 | 工具 | 触发条件 |
|---|---|---|
| 智能回归检测 | scripts/smart_commit_analyzer.py | 始终触发 |
| AI深度分析 | scripts/analyze_commits_ai.py | 当配置了DEEPSEEK_API_KEY时 |
Key Files
核心文件
| File | Purpose |
|---|---|
| Main regression detection tool |
| Auto-generated validation rules |
| AI-powered analysis |
| Git history parser |
| GitHub Actions workflow |
| 文件 | 用途 |
|---|---|
| 核心回归检测工具 |
| 自动生成的验证规则 |
| 基于AI的分析工具 |
| Git历史解析工具 |
| GitHub Actions工作流 |
When to Run
运行时机
- Before committing:
python3 scripts/smart_commit_analyzer.py - Before merging PR: Automatic via GitHub Actions
- After pulling updates:
python3 scripts/smart_commit_analyzer.py --validate - Investigating regressions:
python3 scripts/smart_commit_analyzer.py --show-rules
- 提交代码前:
python3 scripts/smart_commit_analyzer.py - 合并PR前:通过GitHub Actions自动运行
- 拉取更新后:
python3 scripts/smart_commit_analyzer.py --validate - 排查回归问题时:
python3 scripts/smart_commit_analyzer.py --show-rules
Interpreting Results
结果解读
| Status | Meaning | Action |
|---|---|---|
| ✅ Passed | Pattern found in code | None |
| ❌ Failed | Pattern missing (potential regression) | Investigate |
| ⚠️ Warning | Pattern may have been refactored | Review |
| ⏭️ Skipped | File not found (renamed/deleted) | Update rules |
| 状态 | 含义 | 操作建议 |
|---|---|---|
| ✅ 通过 | 代码中存在目标模式 | 无需操作 |
| ❌ 失败 | 目标模式缺失(潜在回归问题) | 需排查 |
| ⚠️ 警告 | 模式可能已被重构 | 需审核 |
| ⏭️ 跳过 | 文件未找到(已重命名/删除) | 更新规则 |