Skip to content

feat(core): implement .gitbunignore support to exclude low-signal files (#53)#54

Open
Xploit-Ghost wants to merge 4 commits into
nirvik34:mainfrom
Xploit-Ghost:main
Open

feat(core): implement .gitbunignore support to exclude low-signal files (#53)#54
Xploit-Ghost wants to merge 4 commits into
nirvik34:mainfrom
Xploit-Ghost:main

Conversation

@Xploit-Ghost
Copy link
Copy Markdown

@Xploit-Ghost Xploit-Ghost commented May 31, 2026

Description

This PR introduces support for a .gitbunignore file at the repository root to prevent large, auto-generated, or irrelevant files from being passed to the AI diff analyzer.

By filtering the staged files array before diff generation, we prevent unnecessary token usage, improve local LLM generation speeds, and maintain high-quality commit summaries.

Changes Made

  • Dependency Added: Integrated the ignore library to handle standard .gitignore syntax matching.
  • Core Logic: Modified getStagedFiles() in src/git/getStagedFiles.ts to intercept the output of git diff --cached --name-status.
  • Out-of-the-Box Defaults: If no .gitbunignore is present, it safely defaults to ignoring heavy files like package-lock.json, yarn.lock, pnpm-lock.yaml, and dist/ or build/ directories.

Resolves #53


It's a pleasure working with this project!
Could a maintainer please review and add the gssoc:approved and level labels? Thank you!

Summary by CodeRabbit

  • New Features
    • Added .gitbunignore support to customize excluded files during analysis
    • Default exclusions applied for common build artifacts, dependencies, and lock files when no custom configuration exists

@vercel
Copy link
Copy Markdown

vercel Bot commented May 31, 2026

@Xploit-Ghost is attempting to deploy a commit to the nirvik34's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

Warning

Review limit reached

@Xploit-Ghost, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 39 minutes and 26 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c207ee6-b303-4b0d-b323-a1a1202a8b7b

📥 Commits

Reviewing files that changed from the base of the PR and between bced38d and 42dfbc3.

📒 Files selected for processing (1)
  • src/git/getStagedFiles.ts

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid option: expected one of "chill"|"assertive" at "reviews.profile"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

This PR introduces .gitbunignore support to gitbun's staged file analysis pipeline. The ignore library is added as a dependency, a getFilteredFiles() utility is created in fileFilter.ts to handle pattern-based exclusions, and getStagedFiles() is updated to apply those ignore rules to filter staged files before passing them to the AI engine.

Changes

.gitbunignore Support

Layer / File(s) Summary
Ignore library dependency
package.json
The ignore library version ^7.0.5 is added as a runtime dependency.
File filter utility
src/analyzer/fileFilter.ts
getFilteredFiles() exported function loads ignore patterns from .gitbunignore (or uses defaults for lockfiles, dist/, build/, node_modules/) and filters a file list accordingly.
Staged files ignore filtering
src/git/getStagedFiles.ts
Imports fs, path, and ignore; refactors the staged-file parsing logic; and applies .gitbunignore-based filtering to exclude matched files from the returned staged file list.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • nirvik34/gitbun#13: Earlier work introducing fileFilter.ts utilities; this PR extends it with .gitbunignore and default ignore pattern handling.

Suggested labels

type: feature, level: advanced, quality:clean

Suggested reviewers

  • nirvik34
  • 2PieRadian

Poem

🐰 A filter now blocks the noise and clutter,
Keeping locked files and build bins in the gutter,
The ignore file rules what the AI shall see,
Only code that matters, oh so clean and free!
.gitbunignore whispers: less is more, you see!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing .gitbunignore support to exclude files from analysis, which aligns with the PR's primary objective.
Linked Issues check ✅ Passed The PR implementation fully addresses all coding requirements from issue #53: adds ignore library dependency, implements .gitbunignore file parsing, filters git diff output, and provides sensible default exclusions.
Out of Scope Changes check ✅ Passed All changes directly support the .gitbunignore feature implementation with no extraneous modifications detected across package.json, fileFilter.ts, and getStagedFiles.ts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
src/git/getStagedFiles.ts (1)

38-60: ⚡ Quick win

Reuse getFilteredFiles instead of duplicating the ignore logic, and drop the stray [cite: 10] comment artifacts.

This block duplicates the .gitbunignore loading and fallback already implemented in getFilteredFiles (src/analyzer/fileFilter.ts), and the two default lists have already diverged. Map the staged paths through the shared helper to keep behavior consistent. Also, the inline comments on Lines 44 and 48 contain leftover [cite: 10] artifacts that should be removed.

♻️ Suggested consolidation
-import fs from "fs";
-import path from "path";
-import ignore from "ignore";
+import { getFilteredFiles } from "../analyzer/fileFilter";
-  // --- GITBUNIGNORE FILTERING LOGIC ---
-  const ig = ignore();
-  const rootDir = process.cwd();
-  const ignorePath = path.join(rootDir, ".gitbunignore");
-
-  // 1. Check if .gitbunignore exists at the root[cite: 10]
-  if (fs.existsSync(ignorePath)) {
-    ig.add(fs.readFileSync(ignorePath).toString());
-  } else {
-    // 2. Default out-of-the-box exclusions to save tokens[cite: 10]
-    ig.add([
-      "package-lock.json",
-      "yarn.lock",
-      "pnpm-lock.yaml",
-      "dist/",
-      "build/",
-      "node_modules/",
-    ]);
-  }
-
-  // 3. Filter the staged files array before returning it
-  return files.filter((file) => !ig.ignores(file.path));
+  // Filter staged files against .gitbunignore (or built-in defaults).
+  const keep = new Set(getFilteredFiles(files.map((f) => f.path), process.cwd()));
+  return files.filter((file) => keep.has(file.path));

This assumes getFilteredFiles is updated to own the canonical default list (see fileFilter.ts comment).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/git/getStagedFiles.ts` around lines 38 - 60, Replace the duplicated
.gitbunignore loading and default-exclusion logic in getStagedFiles by reusing
the existing getFilteredFiles helper: map the staged file paths through
getFilteredFiles (or call getFilteredFiles with the staged files) instead of
creating a new ignore() instance and default list, and remove the stray "[cite:
10]" comment artifacts; specifically update the return logic that currently does
files.filter((file) => !ig.ignores(file.path)) to delegate to getFilteredFiles
(ensuring getFilteredFiles is the canonical source of defaults) and delete the
two inline [cite: 10] comments.
src/analyzer/fileFilter.ts (1)

6-17: ⚡ Quick win

getFilteredFiles appears unused and its default .gitbunignore fallback drifts from getStagedFiles

  • Repo-wide search shows getFilteredFiles is only defined in src/analyzer/fileFilter.ts and has no call sites.
  • Default exclusions differ: getFilteredFiles uses ['package-lock.json', 'dist/', 'build/', 'node_modules/'], while src/git/getStagedFiles.ts also excludes yarn.lock and pnpm-lock.yaml.

Consolidate the fallback ignore patterns into a single shared constant (and/or have getStagedFiles call this helper), or remove the unused helper to avoid behavior drift.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/analyzer/fileFilter.ts` around lines 6 - 17, getFilteredFiles is unused
and its fallback ignore list drifts from getStagedFiles: either remove
getFilteredFiles or consolidate the fallback list into a shared constant and use
it in both places. Create and export a single DEFAULT_IGNORES constant
containing ['package-lock.json', 'yarn.lock', 'pnpm-lock.yaml', 'dist/',
'build/', 'node_modules/'] (place it in a shared module or in
src/analyzer/fileFilter.ts and export it), update getFilteredFiles to use
DEFAULT_IGNORES instead of its inline array, and update
src/git/getStagedFiles.ts to import and use DEFAULT_IGNORES; if you choose
removal, delete the getFilteredFiles function and replace any future uses with
the shared helper or the existing staged-file logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/git/getStagedFiles.ts`:
- Around line 41-46: The code builds ignorePath using process.cwd() in
getStagedFiles (rootDir / ignorePath), which misses a repository-level
.gitbunignore when run from subdirectories; change the logic that defines
rootDir/ignorePath to resolve the git repo root (e.g., run git rev-parse
--show-toplevel via child_process.execSync or a helper like getRepoRoot) and
then set ignorePath = path.join(repoRoot, ".gitbunignore"); keep a safe fallback
to process.cwd() if git fails, and leave the rest of the .gitbunignore handling
(fs.existsSync + ig.add(...)) unchanged.

---

Nitpick comments:
In `@src/analyzer/fileFilter.ts`:
- Around line 6-17: getFilteredFiles is unused and its fallback ignore list
drifts from getStagedFiles: either remove getFilteredFiles or consolidate the
fallback list into a shared constant and use it in both places. Create and
export a single DEFAULT_IGNORES constant containing ['package-lock.json',
'yarn.lock', 'pnpm-lock.yaml', 'dist/', 'build/', 'node_modules/'] (place it in
a shared module or in src/analyzer/fileFilter.ts and export it), update
getFilteredFiles to use DEFAULT_IGNORES instead of its inline array, and update
src/git/getStagedFiles.ts to import and use DEFAULT_IGNORES; if you choose
removal, delete the getFilteredFiles function and replace any future uses with
the shared helper or the existing staged-file logic.

In `@src/git/getStagedFiles.ts`:
- Around line 38-60: Replace the duplicated .gitbunignore loading and
default-exclusion logic in getStagedFiles by reusing the existing
getFilteredFiles helper: map the staged file paths through getFilteredFiles (or
call getFilteredFiles with the staged files) instead of creating a new ignore()
instance and default list, and remove the stray "[cite: 10]" comment artifacts;
specifically update the return logic that currently does files.filter((file) =>
!ig.ignores(file.path)) to delegate to getFilteredFiles (ensuring
getFilteredFiles is the canonical source of defaults) and delete the two inline
[cite: 10] comments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: adc801d1-2dc9-46cb-b9f9-7dd151808d28

📥 Commits

Reviewing files that changed from the base of the PR and between 12516ec and bced38d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • package.json
  • src/analyzer/fileFilter.ts
  • src/git/getStagedFiles.ts

Comment thread src/git/getStagedFiles.ts Outdated
@Xploit-Ghost
Copy link
Copy Markdown
Author

@nirvik34 Issue #1620 is resolved ! Let me know if it needs more improvement or looks good to merge!
Please add the quality:exceptional and level labels. Thank you for your time !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Implement .gitbunignore Support to Exclude Files from AI Diff Analysis

1 participant