commit-analysis

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Commit Analysis & Regression Detection

提交分析与回归检测

Overview

概述

Automated tools for detecting regressions and analyzing code changes:
ToolPurposeSpeed
scripts/smart_commit_analyzer.pyAuto-evolving regression detectionFast
scripts/analyze_commits_ai.pyAI semantic analysis (DeepSeek)Slow
scripts/analyze_git_changes.pyGit history statisticsFast
scripts/validate_commit_fixes.pyLegacy manual rules (deprecated)Fast
用于检测回归问题和分析代码变更的自动化工具:
工具用途速度
scripts/smart_commit_analyzer.py可自动演进的回归检测快速
scripts/analyze_commits_ai.pyAI语义分析(基于DeepSeek)缓慢
scripts/analyze_git_changes.pyGit历史统计分析快速
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
undefined
bash
undefined

Full 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
undefined
python3 scripts/smart_commit_analyzer.py --json
undefined

Expected 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
⏭️  跳过: 0

How 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
DEEPSEEK_API_KEY
environment variable.
bash
undefined
需要配置
DEEPSEEK_API_KEY
环境变量。
bash
undefined

Analyze 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
undefined
python3 scripts/analyze_commits_ai.py --commits 10 --json
undefined

Git History Analysis

Git历史分析

bash
undefined
bash
undefined

Analyze 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
undefined
python3 scripts/analyze_git_changes.py --commits 100
undefined

GitHub Actions Integration

GitHub Actions集成

These tools run automatically on every push/PR via
.github/workflows/commit-analysis.yml
:
JobToolTrigger
Smart Regression Detectionscripts/smart_commit_analyzer.pyAlways
AI Deep Analysisscripts/analyze_commits_ai.pyIf DEEPSEEK_API_KEY set
这些工具会通过
.github/workflows/commit-analysis.yml
在每次推送/PR时自动运行:
任务工具触发条件
智能回归检测scripts/smart_commit_analyzer.py始终触发
AI深度分析scripts/analyze_commits_ai.py当配置了DEEPSEEK_API_KEY时

Key Files

核心文件

FilePurpose
scripts/smart_commit_analyzer.py
Main regression detection tool
configs/auto_generated_rules.json
Auto-generated validation rules
scripts/analyze_commits_ai.py
AI-powered analysis
scripts/analyze_git_changes.py
Git history parser
.github/workflows/commit-analysis.yml
GitHub Actions workflow
文件用途
scripts/smart_commit_analyzer.py
核心回归检测工具
configs/auto_generated_rules.json
自动生成的验证规则
scripts/analyze_commits_ai.py
基于AI的分析工具
scripts/analyze_git_changes.py
Git历史解析工具
.github/workflows/commit-analysis.yml
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

结果解读

StatusMeaningAction
✅ PassedPattern found in codeNone
❌ FailedPattern missing (potential regression)Investigate
⚠️ WarningPattern may have been refactoredReview
⏭️ SkippedFile not found (renamed/deleted)Update rules
状态含义操作建议
✅ 通过代码中存在目标模式无需操作
❌ 失败目标模式缺失(潜在回归问题)需排查
⚠️ 警告模式可能已被重构需审核
⏭️ 跳过文件未找到(已重命名/删除)更新规则