feat: support filtering commits by paths - #331
Conversation
Co-authored-by: Stephen Hebert <stephenjosephhebert@gmail.com>
📝 WalkthroughWalkthroughAdds an optional repeatable ChangesCommit path filtering
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
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
README.mdsrc/commands/default.tssrc/config.tssrc/git.tstest/git.test.ts
| 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 | ||
| ); |
There was a problem hiding this comment.
🎯 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.
| 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.
resolves #232
adds a
--pathcli flag to only include commits touching given paths in the changelogthere is already an older PR for this #233, but I thought I'd include some tests for it too, and I think that
pathis a more suitable name for the argumentSummary by CodeRabbit
New Features
--pathCLI option to limit changelog generation to commits affecting specific repository paths.Documentation
--pathoption.Tests