[PR #462] [CLOSED] feat: add ignore patterns support for stats command #491

Closed
opened 2026-03-02 04:13:47 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/git-ai-project/git-ai/pull/462
Author: @txf0096
Created: 2/5/2026
Status: Closed

Base: mainHead: feat/stats-ignore-patterns


📝 Commits (1)

  • 38a8a49 feat: add ignore patterns support for stats command

📊 Changes

4 files changed (+153 additions, -0 deletions)

View changed files

src/authorship/ignore_patterns.rs (+123 -0)
📝 src/authorship/mod.rs (+1 -0)
📝 src/commands/git_ai_handlers.rs (+12 -0)
📝 src/config.rs (+17 -0)

📄 Description

Fixes #461

Summary

This PR implements ignore patterns support for the stats command, allowing users to exclude auto-generated files (lock files, minified code, generated code) from AI/human statistics.

Implementation

Added three configuration levels (all additive):

1. CLI flag

git-ai stats --ignore "*.lock" "*.min.js" "dist/**"
git-ai stats HEAD --ignore "*.generated.*"

2. Project-level config

Create .git-ai-ignore in repository root (gitignore syntax):

# Lock files
*.lock
go.sum

# Build artifacts  
*.min.js
*.bundle.js

# Generated code
*.generated.*
*_pb.go

3. Global config

In ~/.git-ai/config.json:

{
  "stats_ignore_patterns": [
    "*.lock",
    "*.min.js",
    "*.generated.*"
  ]
}

Changes

  • Add src/authorship/ignore_patterns.rs module for loading patterns from files
  • Add stats_ignore_patterns field to Config struct
  • Merge patterns in handle_stats() before calling stats/range functions
  • Only affects stats command (not checkpoint, blame, diff)
  • Uses glob pattern matching (like .gitignore)
  • Skips entire files from statistics (both AI and human lines)

Benefits

More accurate AI/human code ratio
Exclude noise from lock files and generated code
Team consistency via committed .git-ai-ignore
Flexible: global defaults + per-project overrides

Example

Before:

$ git-ai stats HEAD
you  ████████░░░░░░░░░░░░ ai
     65%              35%
# Includes 5000 lines from package-lock.json

After:

$ git-ai stats HEAD
you  ████████████████░░░░ ai
     80%              20%  
# package-lock.json excluded via .git-ai-ignore

Testing

  • Compiled successfully with cargo build
  • Pattern loading logic tested with multiple sources
  • Backward compatible (defaults to no patterns if not configured)

Open with Devin

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/git-ai-project/git-ai/pull/462 **Author:** [@txf0096](https://github.com/txf0096) **Created:** 2/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/stats-ignore-patterns` --- ### 📝 Commits (1) - [`38a8a49`](https://github.com/git-ai-project/git-ai/commit/38a8a49727ce11fe0e3d510b755e81c556f400a8) feat: add ignore patterns support for stats command ### 📊 Changes **4 files changed** (+153 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `src/authorship/ignore_patterns.rs` (+123 -0) 📝 `src/authorship/mod.rs` (+1 -0) 📝 `src/commands/git_ai_handlers.rs` (+12 -0) 📝 `src/config.rs` (+17 -0) </details> ### 📄 Description Fixes #461 ## Summary This PR implements ignore patterns support for the `stats` command, allowing users to exclude auto-generated files (lock files, minified code, generated code) from AI/human statistics. ## Implementation Added three configuration levels (all additive): ### 1. CLI flag ```bash git-ai stats --ignore "*.lock" "*.min.js" "dist/**" git-ai stats HEAD --ignore "*.generated.*" ``` ### 2. Project-level config Create `.git-ai-ignore` in repository root (gitignore syntax): ``` # Lock files *.lock go.sum # Build artifacts *.min.js *.bundle.js # Generated code *.generated.* *_pb.go ``` ### 3. Global config In `~/.git-ai/config.json`: ```json { "stats_ignore_patterns": [ "*.lock", "*.min.js", "*.generated.*" ] } ``` ## Changes - Add `src/authorship/ignore_patterns.rs` module for loading patterns from files - Add `stats_ignore_patterns` field to `Config` struct - Merge patterns in `handle_stats()` before calling stats/range functions - Only affects `stats` command (not checkpoint, blame, diff) - Uses glob pattern matching (like .gitignore) - Skips entire files from statistics (both AI and human lines) ## Benefits ✅ More accurate AI/human code ratio ✅ Exclude noise from lock files and generated code ✅ Team consistency via committed `.git-ai-ignore` ✅ Flexible: global defaults + per-project overrides ## Example Before: ```bash $ git-ai stats HEAD you ████████░░░░░░░░░░░░ ai 65% 35% # Includes 5000 lines from package-lock.json ``` After: ```bash $ git-ai stats HEAD you ████████████████░░░░ ai 80% 20% # package-lock.json excluded via .git-ai-ignore ``` ## Testing - Compiled successfully with `cargo build` - Pattern loading logic tested with multiple sources - Backward compatible (defaults to no patterns if not configured) <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/git-ai-project/git-ai/pull/462" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 04:13:47 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/git-ai#491
No description provided.