feat(bump): add commit filter pattern - #2078
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2078 +/- ##
==========================================
+ Coverage 98.19% 98.31% +0.11%
==========================================
Files 61 61
Lines 2829 2851 +22
==========================================
+ Hits 2778 2803 +25
+ Misses 51 48 -3 ☔ View full report in Codecov by Harness. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> commitizen-tools#2075
110defc to
1e56d63
比较
|
How is this any different from |
|
To illustrate the use case, consider the example commit sequence from #2075. In this monorepo, commits related to applications AppA and/or AppB are identified through a custom When calculating the version bump for AppA, only commits that affect AppA should be considered. In this example, (?s)^.*Applications:.*'AppA'.*\].*This pattern selects only commits that relate to
As implemented today in for commit in commits:
for message in commit.message.split("\n"):
result = select_pattern.search(message)(where By contrast, return [commit for commit in commits if select_pattern.match(commit.message)](where I do not think Today, Commitizen evaluates each line of a commit message against For that reason, I see |
|
Yes, but it's the same, now we evaluate twice the commit message. Why not a setting like |
|
Mmh, I would still like to support commit messages such as the following: When calculating the version bump for AppA, I would first want to identify this commit as relevant using a (?s)^.*Applications:.*'AppA'.*\].*The commit would then participate in the bump calculation. After that, I would still want the existing This is why I currently do not see how a setting such as
In my use case, both behaviors are needed at the same time. The proposed This would also be analogous to |
Manny7717
left a comment
There was a problem hiding this comment.
Verified locally on head 1e56d63. The feature is correctly scoped and the precedence chain is right: cz class attribute (None for custom cz classes, .* default for conventional/customize) -> top-level bump_commit_filter_pattern config -> DEFAULT_SETTINGS fallback, applied consistently in both bump and version commands.
What I re-ran:
filter_commitsedge cases: default.*keeps all commits (backward compatible), anchoredre.matchat message start, alternation patterns, and a pattern matching zero commits -> empty list.- Empty filtered list feeds
find_increment-> returns None, and the new integration testtest_bump_commit_filter_pattern_excludes_all_commitsconfirms the user-facingNoneIncrementExit("The commits found are not eligible to be bumped") rather than a crash. Customize提交Czattr wiring:customize.bump_commit_filter_patternoverrides via the existing setattr loop; plain class default otherwise. Consistent withbump_patternhandling.- Targeted suites (test_bump_command, test_version_command, test_bump_find_increment, test_conf, test_cz_customize): 345 passed. Full suite: only failure is
test_bump_pre_commit_changelog[True-pre-commit], which fails identically on base 4184174 (changelog markdown-escaping env difference) — zero new failures. - ruff + mypy clean.
Docs (bump.md, configuration_file.md, monorepo_guidance.md) explain the feature and its interaction with bump_pattern. No issues found.
Description
This change adds support for filtering commits before Commitizen evaluates them for version bumps by introducing a new
bump_commit_filter_patternsetting.The new setting defaults to
.*, so existing projects keep the current behavior. When configured,cz bumpandcz version --next USE_GIT_COMMITSonly consider commits whose full message matches the filter pattern before applying the existing bump rules. This is particularly useful for monorepos where only a subset of commits should affect a package's version.The pull request also updates the related documentation and adds regression tests covering the new filtering behavior and fallback paths.
Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: GitHub Copilot CLI following the guidelines
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsDocumentation Changes
uv run poe doclocally to ensure the documentation pages renders correctlyExpected Behavior
项目 can opt into filtering commits used for bump calculation without changing the default behavior for existing users. With
bump_commit_filter_patternconfigured, unrelated commits are ignored beforebump_patternis applied, socz bumpandcz version --next USE_GIT_COMMITSderive the next version only from relevant commits.Steps to Test This Pull Request
bump_commit_filter_patternfor a subset of commit messages, for example^fix\(library-b\):.cz bump --dry-runorcz bump --get-nextand confirm that only matching commits affect the calculated increment.cz version --project --next USE_GIT_COMMITSand confirm it reports the version derived from the filtered commit set.Additional Context
Related discussion: #2075
Manual testing and validation performed during development included targeted pytest coverage for:
USE_GIT_COMMITSnext-version calculation with filters