|
7 | 7 | import questionary |
8 | 8 |
|
9 | 9 | from commitizen import bump, factory, git, hooks, out |
10 | | -from commitizen.bump_rule import find_increment_by_callable |
| 10 | +from commitizen.bump_rule import OldSchoolBumpRule, find_increment_by_callable |
11 | 11 | from commitizen.changelog_formats import get_changelog_format |
12 | 12 | from commitizen.commands.changelog import Changelog |
13 | 13 | from commitizen.config import BaseConfig |
@@ -124,27 +124,31 @@ def find_increment(self, commits: list[git.GitCommit]) -> Increment | None: |
124 | 124 | # Update the bump map to ensure major version doesn't increment. |
125 | 125 | is_major_version_zero: bool = self.bump_settings["major_version_zero"] |
126 | 126 |
|
127 | | - if rule := self.cz.bump_rule: |
128 | | - return find_increment_by_callable( |
129 | | - (commit.message for commit in commits), |
130 | | - lambda x: rule.get_increment(x, is_major_version_zero), |
131 | | - ) |
132 | | - |
133 | | - bump_map = ( |
134 | | - self.cz.bump_map_major_version_zero |
135 | | - if is_major_version_zero |
136 | | - else self.cz.bump_map |
| 127 | + # Fallback to old school bump rule if no bump rule is provided |
| 128 | + rule = self.cz.bump_rule or OldSchoolBumpRule( |
| 129 | + *self._get_validated_cz_bump(), |
| 130 | + ) |
| 131 | + return find_increment_by_callable( |
| 132 | + (commit.message for commit in commits), |
| 133 | + lambda x: rule.get_increment(x, is_major_version_zero), |
137 | 134 | ) |
138 | | - bump_pattern = self.cz.bump_pattern |
139 | 135 |
|
140 | | - if not bump_map or not bump_pattern: |
| 136 | + def _get_validated_cz_bump( |
| 137 | + self, |
| 138 | + ) -> tuple[str, dict[str, Increment], dict[str, Increment]]: |
| 139 | + """For fixing the type errors""" |
| 140 | + bump_pattern = self.cz.bump_pattern |
| 141 | + bump_map = self.cz.bump_map |
| 142 | + bump_map_major_version_zero = self.cz.bump_map_major_version_zero |
| 143 | + if not bump_pattern or not bump_map or not bump_map_major_version_zero: |
141 | 144 | raise NoPatternMapError( |
142 | 145 | f"'{self.config.settings['name']}' rule does not support bump" |
143 | 146 | ) |
144 | | - increment = bump.find_increment( |
145 | | - commits, regex=bump_pattern, increments_map=bump_map |
| 147 | + |
| 148 | + return cast( |
| 149 | + tuple[str, dict[str, Increment], dict[str, Increment]], |
| 150 | + (bump_pattern, bump_map, bump_map_major_version_zero), |
146 | 151 | ) |
147 | | - return increment |
148 | 152 |
|
149 | 153 | def __call__(self) -> None: # noqa: C901 |
150 | 154 | """Steps executed to bump.""" |
|
0 commit comments