Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6096b68

Browse files
committed
feat: make major_version_zero customizable by third parties
before this commit, major_version_zero would only work with conventional commits, as the value used was not exposed to other cz rules
1 parent d11ee96 commit 6096b68

File tree

6 files changed

+25
-10
lines changed

6 files changed

+25
-10
lines changed

‎commitizen/commands/bump.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import questionary
66
from packaging.version import InvalidVersion, Version
77

8-
from commitizen import bump, cmd, defaults, factory, git, hooks, out, version_types
8+
from commitizen import bump, cmd, factory, git, hooks, out, version_types
99
from commitizen.commands.changelog import Changelog
1010
from commitizen.config import BaseConfig
1111
from commitizen.exceptions import (
@@ -86,8 +86,16 @@ def is_initial_tag(self, current_tag_version: str, is_yes: bool = False) -> bool
8686
return is_initial
8787

8888
def find_increment(self, commits: List[git.GitCommit]) -> Optional[str]:
89+
# Update the bump map to ensure major version doesn't increment.
90+
is_major_version_zero: bool = self.bump_settings["major_version_zero"]
91+
# self.cz.bump_map = defaults.bump_map_major_version_zero
92+
bump_map = (
93+
self.cz.bump_map_major_version_zero
94+
if is_major_version_zero
95+
else self.cz.bump_map
96+
)
8997
bump_pattern = self.cz.bump_pattern
90-
bump_map=self.cz.bump_map
98+
9199
if not bump_map or not bump_pattern:
92100
raise NoPatternMapError(
93101
f"'{self.config.settings['name']}' rule does not support bump"
@@ -153,9 +161,6 @@ def __call__(self): # noqa: C901
153161
f"--major-version-zero is meaningless for current version {current_version}"
154162
)
155163

156-
# Update the bump map to ensure major version doesn't increment.
157-
self.cz.bump_map = defaults.bump_map_major_version_zero
158-
159164
current_tag_version: str = bump.normalize_tag(
160165
current_version,
161166
tag_format=tag_format,

‎commitizen/cz/base.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
class BaseCommitizen(metaclass=ABCMeta):
1212
bump_pattern: Optional[str] = None
1313
bump_map: Optional[Dict[str, str]] = None
14+
bump_map_major_version_zero: Optional[Dict[str, str]] = None
1415
default_style_config: List[Tuple[str, str]] = [
1516
("qmark", "fg:#ff9d00 bold"),
1617
("question", "bold"),

‎commitizen/cz/conventional_commits/conventional_commits.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def parse_subject(text):
3030
class ConventionalCommitsCz(BaseCommitizen):
3131
bump_pattern = defaults.bump_pattern
3232
bump_map = defaults.bump_map
33+
bump_map_major_version_zero = defaults.bump_map_major_version_zero
3334
commit_parser = defaults.commit_parser
3435
version_parser = defaults.version_parser
3536
change_type_map = {

‎commitizen/cz/customize/customize.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
class CustomizeCommitsCz(BaseCommitizen):
1818
bump_pattern = defaults.bump_pattern
1919
bump_map = defaults.bump_map
20+
bump_map_major_version_zero = defaults.bump_map_major_version_zero
2021
change_type_order = defaults.change_type_order
2122

2223
def __init__(self, config: BaseConfig):
@@ -34,6 +35,12 @@ def __init__(self, config: BaseConfig):
3435
if custom_bump_map:
3536
self.bump_map = custom_bump_map
3637

38+
custom_bump_map_major_version_zero = self.custom_settings.get(
39+
"bump_map_major_version_zero"
40+
)
41+
if custom_bump_map_major_version_zero:
42+
self.bump_map_major_version_zero = custom_bump_map_major_version_zero
43+
3744
custom_change_type_order = self.custom_settings.get("change_type_order")
3845
if custom_change_type_order:
3946
self.change_type_order = custom_change_type_order

‎commitizen/defaults.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
class CzSettings(TypedDict, total=False):
1616
bump_pattern: str
1717
bump_map: "OrderedDict[str, str]"
18+
bump_map_major_version_zero: "OrderedDict[str, str]"
1819
change_type_order: List[str]
1920

2021
questions: Questions

‎tests/conftest.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ class SemverCommitizen(BaseCommitizen):
143143
"minor": "MINOR",
144144
"patch": "PATCH",
145145
}
146-
# bump_map_major_version_zero = {
147-
# "major": "MINOR",
148-
# "minor": "MINOR",
149-
# "patch": "PATCH",
150-
# }
146+
bump_map_major_version_zero = {
147+
"major": "MINOR",
148+
"minor": "MINOR",
149+
"patch": "PATCH",
150+
}
151151
changelog_pattern = r"^(patch|minor|major)"
152152
commit_parser = r"^(?P<change_type>patch|minor|major)(?:\((?P<scope>[^()\r\n]*)\)|\()?:?\s(?P<message>.+)" # noqa
153153
change_type_map = {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /