Skip to content

feat: add extensible commit filters - #2090

Open
schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:feature/base-commit-filter-hooks
Open

schlotter wants to merge 1 commit into
commitizen-tools:masterfrom
ZEISS:feature/base-commit-filter-hooks

Conversation

@schlotter

Copy link
Copy Markdown
Contributor

Description

Add convention-agnostic commit filtering hooks to BaseCommitizen.

Custom rules can now override one shared filter_commits method or the
operation-specific filter_commits_before_bump and
filter_commits_before_changelog methods. The hooks run before bump calculation
and changelog generation without changing the existing line-by-line
bump_pattern behavior.

cz version --next USE_GIT_COMMITS uses the bump hook as well, so all
commit-derived version calculations remain consistent. cz check is
intentionally unchanged.

This is an alternative implementation for
commitizen-tools/commitizen#2075
alongside
commitizen-tools/commitizen#2078.
Instead of adding a built-in filtering regex, it provides the generic extension
point proposed in the PR discussion.

Checklist

Was generative AI tooling used to co-author this PR?

  • Yes (GitHub Copilot CLI)

Generated-by: GitHub Copilot CLI following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
    • Formatting, Ruff, mypy, and commit-message validation passed.
    • The suite passed 1,313 tests, but two pre-existing
      test_bump_pre_commit_changelog cases could not install prettier/node in
      their isolated hook environments because of local TLS certificate errors.
    • A coverage run excluding that network-dependent test function passed all
      1,309 selected tests with 98% coverage.
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run uv run poe doc:build locally to ensure the documentation renders correctly
  • Check and fix any broken links (internal or external)

The changed documentation also passes the blacken-docs and codespell
pre-commit hooks.

Expected Behavior

Existing rules retain all commits by default, so current bump and changelog
behavior is unchanged.

A Python commit rule can override filter_commits to select commits using the
full commit message. Both bump calculation and changelog generation then process
only the selected commits. A rule can instead override an operation-specific
method when bump and changelog selection should differ.

Steps to Test This Pull Request

  1. Create a custom rule that subclasses ConventionalCommitsCz and overrides
    filter_commits to select commits containing Applications: ['AppA'].
  2. Add an AppB feat commit and an AppA fix commit after the current version
    tag.
  3. Run cz bump --get-next and confirm the next version is a patch rather than a
    minor release.
  4. Run cz version --project --next USE_GIT_COMMITS and confirm it reports the
    same patch version.
  5. Run cz changelog --dry-run and confirm only the AppA commit is included.
  6. Use the built-in rule without an override and confirm all commits remain
    available to bump and changelog processing.

Additional Context

The documentation includes a complete ConventionalCommitsCz plugin example
that reads a plugin-owned app = "AppA" key from [tool.commitizen] and filters
the full Applications: [...] metadata line.

This change does not add a core configuration setting, alter cz check, modify
CHANGELOG.md, or update project versions.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.27%. Comparing base (4967717) to head (0a593cd).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2090   +/-   ##
=======================================
  Coverage   98.26%   98.27%           
=======================================
  Files          61       61           
  Lines        2829     2836    +7     
=======================================
+ Hits         2780     2787    +7     
  Misses         49       49           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@schlotter
schlotter force-pushed the feature/base-commit-filter-hooks branch from 9ba70f0 to 0a593cd Compare September 17, 2026 20:30
@schlotter
schlotter marked this pull request as ready for review September 17, 2026 20:38

@woile woile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants