feat(ConventionalCommitsCZ): add support for customizable change type choices and bump map overrides#2006
Conversation
… choices and bump map overrides
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2006 +/- ##
==========================================
+ Coverage 98.24% 99.08% +0.84%
==========================================
Files 61 61
Lines 2785 2836 +51
==========================================
+ Hits 2736 2810 +74
+ Misses 49 26 -23 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
This PR extends the cz_conventional_commits convention to support user configuration via new override and extend settings, enabling customization of bump/changelog parsing and change type choice lists without switching to cz_customize.
Changes:
- Add
override/extendtyped settings structures to the globalSettingsmodel. - Teach
ConventionalCommitsCzto apply override/extend settings and isolate mutable defaults per instance. - Add tests covering precedence (override > extend), supported settings application, and mutation isolation between instances.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 39 comments.
| File | Description |
|---|---|
commitizen/cz/conventional_commits/conventional_commits.py |
Adds per-instance isolation and applies override/extend settings; refactors change type choices into a reusable attribute. |
commitizen/defaults.py |
Extends the typed settings model with override/extend sections and typed change_type_choices. |
tests/test_cz_conventional_commits.py |
Adds test coverage for override/extend precedence, application behavior, and instance isolation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from commitizen import defaults | ||
| from commitizen.cz.base import BaseCommitizen | ||
| from commitizen.cz.utils import multiple_line_breaker, required_validator | ||
| from commitizen.question import Choice | ||
|
|
||
| if TYPE_CHECKING: | ||
| from commitizen.config import BaseConfig | ||
| from commitizen.question import CzQuestion |
| } | ||
| change_type_choices = [ | ||
| Choice( |
| Choice( | ||
| value="fix", | ||
| name=("fix: A bug fix. Correlates with PATCH in SemVer"), | ||
| key="x", | ||
| ), |
| Choice( | ||
| value="feat", | ||
| name="feat: A new feature. Correlates with MINOR in SemVer", | ||
| key="f", | ||
| ), |
| Choice( | ||
| value="docs", | ||
| name="docs: Documentation only changes", | ||
| key="d", | ||
| ), |
| Choice( | ||
| value="build", | ||
| name=( | ||
| "build: Changes that affect the build system or " | ||
| "external dependencies (example scopes: pip, docker, npm)" | ||
| ), | ||
| key="b", | ||
| ), |
| Choice( | ||
| value="ci", | ||
| name=( | ||
| "ci: Changes to CI configuration files and " | ||
| "scripts (example scopes: GitLabCI)" | ||
| ), | ||
| key="c", | ||
| ), |
| def _apply_override_settings(self, settings: defaults.CzOverrideSettings) -> None: | ||
| if bump_pattern := settings.get("bump_pattern"): | ||
| self.bump_pattern = bump_pattern | ||
| if bump_map := settings.get("bump_map"): | ||
| self.bump_map = OrderedDict(bump_map) | ||
| if bump_map_major_version_zero := settings.get("bump_map_major_version_zero"): | ||
| self.bump_map_major_version_zero = OrderedDict(bump_map_major_version_zero) | ||
| if commit_parser := settings.get("commit_parser"): | ||
| self.commit_parser = commit_parser | ||
| if changelog_pattern := settings.get("changelog_pattern"): | ||
| self.changelog_pattern = changelog_pattern | ||
| if change_type_map := settings.get("change_type_map"): | ||
| self.change_type_map = dict(change_type_map) | ||
| if change_type_choices := settings.get("change_type_choices"): | ||
| self.change_type_choices = [*change_type_choices] | ||
|
|
| def _apply_extend_settings(self, settings: defaults.CzExtendSettings) -> None: | ||
| if bump_pattern := settings.get("bump_pattern"): | ||
| self.bump_pattern = bump_pattern | ||
| if bump_map := settings.get("bump_map"): | ||
| self.bump_map.update(bump_map) | ||
| if bump_map_major_version_zero := settings.get("bump_map_major_version_zero"): | ||
| self.bump_map_major_version_zero.update(bump_map_major_version_zero) | ||
| if commit_parser := settings.get("commit_parser"): | ||
| self.commit_parser = commit_parser | ||
| if changelog_pattern := settings.get("changelog_pattern"): | ||
| self.changelog_pattern = changelog_pattern | ||
| if change_type_map := settings.get("change_type_map"): | ||
| self.change_type_map.update(change_type_map) | ||
| if change_type_choices := settings.get("change_type_choices"): | ||
| self.change_type_choices.extend(change_type_choices) |
| "refactor": "Refactor", | ||
| "perf": "Perf", | ||
| } | ||
| change_type_choices = [ |
|
@Lee-W Could you take a look? You have more context on this feature. |
Description
According to #1385, I've adding
overrideandextendattributes underSettings, basically, the content was inherited usingCzSettings.Checklist
Was generative AI tooling used to co-author this PR?
Code Changes
uv run poe alllocally to ensure this change passes linter check and testsExpected Behavior
Steps to Test This Pull Request
Override
Extend
Additional Context
issue #1385