feat(core): implement .gitbunignore support to exclude low-signal files (#53)#54
feat(core): implement .gitbunignore support to exclude low-signal files (#53)#54Xploit-Ghost wants to merge 4 commits into
Conversation
|
@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. |
|
Warning Review limit reached
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 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. Warning
|
| 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.tsutilities; this PR extends it with.gitbunignoreand 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!
.gitbunignorewhispers: less is more, you see! ✨
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | 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.
Comment @coderabbitai help to get the list of available commands and usage tips.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/git/getStagedFiles.ts (1)
38-60: ⚡ Quick winReuse
getFilteredFilesinstead of duplicating the ignore logic, and drop the stray[cite: 10]comment artifacts.This block duplicates the
.gitbunignoreloading and fallback already implemented ingetFilteredFiles(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
getFilteredFilesis 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
getFilteredFilesappears unused and its default.gitbunignorefallback drifts fromgetStagedFiles
- Repo-wide search shows
getFilteredFilesis only defined insrc/analyzer/fileFilter.tsand has no call sites.- Default exclusions differ:
getFilteredFilesuses['package-lock.json', 'dist/', 'build/', 'node_modules/'], whilesrc/git/getStagedFiles.tsalso excludesyarn.lockandpnpm-lock.yaml.Consolidate the fallback ignore patterns into a single shared constant (and/or have
getStagedFilescall 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
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (3)
package.jsonsrc/analyzer/fileFilter.tssrc/git/getStagedFiles.ts
|
@nirvik34 Issue #1620 is resolved ! Let me know if it needs more improvement or looks good to merge! |
Description
This PR introduces support for a
.gitbunignorefile 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
ignorelibrary to handle standard.gitignoresyntax matching.getStagedFiles()insrc/git/getStagedFiles.tsto intercept the output ofgit diff --cached --name-status..gitbunignoreis present, it safely defaults to ignoring heavy files likepackage-lock.json,yarn.lock,pnpm-lock.yaml, anddist/orbuild/directories.Resolves #53
It's a pleasure working with this project!
Could a maintainer please review and add the
gssoc:approvedandlevellabels? Thank you!Summary by CodeRabbit
.gitbunignoresupport to customize excluded files during analysis