Skip to content

feat: support filtering commits by paths - #331

Open
cernymatej wants to merge 1 commit into
unjs:mainfrom
cernymatej:feat/path-filter
Open

feat: support filtering commits by paths#331
cernymatej wants to merge 1 commit into
unjs:mainfrom
cernymatej:feat/path-filter

Conversation

@cernymatej

@cernymatej cernymatej commented Jul 21, 2026

Copy link
Copy Markdown

resolves #232

adds a --path cli flag to only include commits touching given paths in the changelog
there is already an older PR for this #233, but I thought I'd include some tests for it too, and I think that path is a more suitable name for the argument

Summary by CodeRabbit

  • New Features

    • Added a --path CLI option to limit changelog generation to commits affecting specific repository paths.
    • Supports repeating the option to filter multiple paths, including monorepo workflows.
    • Added path filtering support to changelog configuration.
  • Documentation

    • Updated CLI usage documentation with the new --path option.
  • Tests

    • Added coverage for valid, invalid, and multiple path filters.

Co-authored-by: Stephen Hebert <stephenjosephhebert@gmail.com>
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an optional repeatable --path filter, propagates it through changelog configuration, and applies it to Git commit retrieval. Tests cover root, missing, and existing repository paths.

Changes

Commit path filtering

Layer / File(s) Summary
Path filter configuration and command wiring
src/config.ts, src/commands/default.ts, README.md
Adds the optional paths configuration field, forwards args.path through defaultMain, passes it to getGitDiff, and documents the CLI option.
Git filtering and validation
src/git.ts, test/git.test.ts
Builds optional Git pathspec arguments for single or multiple paths and tests filtered commit results for root, missing, and existing paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant defaultMain
  participant ChangelogConfig
  participant getGitDiff
  participant Git
  CLI->>defaultMain: provide --path values
  defaultMain->>ChangelogConfig: configure paths
  defaultMain->>getGitDiff: pass config.paths
  getGitDiff->>Git: run git log with pathspec
  Git-->>getGitDiff: return filtered commits
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding commit path filtering.
Linked Issues check ✅ Passed The PR implements the optional paths filter for changelog generation and adds tests, matching issue #232.
Out of Scope Changes check ✅ Passed The changes stay focused on path-based commit filtering, docs, and tests with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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.ts`:
- Around line 75-78: Remove the --name-status option from the git log command
constructed in getGitDiff, while preserving the existing commit formatting and
optional pathspec filtering so parsed commit bodies contain only actual message
content.
🪄 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: cdd0ad49-2672-4fef-b2c9-ae805a7fcfac

📥 Commits

Reviewing files that changed from the base of the PR and between 1721588 and 3e585f2.

📒 Files selected for processing (5)
  • README.md
  • src/commands/default.ts
  • src/config.ts
  • src/git.ts
  • test/git.test.ts

Comment thread src/git.ts
Comment on lines 75 to 78
const r = execCommand(
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status`,
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status${pathspec ? ` --${pathspec}` : ""}`,
cwd
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Remove --name-status to prevent commit body pollution.

The --name-status flag modifies the git log output to include a list of modified files for each commit. Because getGitDiff parses everything after the first line as the commit body (via _body.join("\n")), these file lists will be erroneously appended to every commit's body in memory.

This can leak into and pollute changelog descriptions if the commit body contains structured notes like BREAKING CHANGE:. Path filtering with git log -- <paths> works natively and does not require the --name-status flag.

🐛 Proposed fix
   const r = execCommand(
-    `git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status${pathspec ? ` --${pathspec}` : ""}`,
+    `git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b"${pathspec ? ` --${pathspec}` : ""}`,
     cwd
   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const r = execCommand(
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status`,
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b" --name-status${pathspec ? ` --${pathspec}` : ""}`,
cwd
);
const r = execCommand(
`git --no-pager log "${from ? `${from}...` : ""}${to}" --pretty="----%n%s|%h|%an|%ae%n%b"${pathspec ? ` --${pathspec}` : ""}`,
cwd
);
🤖 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.ts` around lines 75 - 78, Remove the --name-status option from the
git log command constructed in getGitDiff, while preserving the existing commit
formatting and optional pathspec filtering so parsed commit bodies contain only
actual message content.

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.

Support optional commit paths filter

1 participant