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 2eaf52c

Browse files
docs(CustomBumpRule): add docstring
1 parent 0245469 commit 2eaf52c

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

‎commitizen/bump_rule.py‎

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,55 @@ def __init__(
165165
bump_map: Mapping[str, SemVerIncrement],
166166
bump_map_major_version_zero: Mapping[str, SemVerIncrement],
167167
):
168+
"""Initialize a custom bump rule for version incrementing.
169+
170+
This constructor creates a rule that determines how version numbers should be
171+
incremented based on commit messages. It validates and compiles the provided
172+
pattern and maps for use in version bumping.
173+
174+
The fallback logic is used for backward compatibility.
175+
176+
Args:
177+
bump_pattern: A regex pattern string used to match commit messages.
178+
Example: r"^((?P<major>major)|(?P<minor>minor)|(?P<patch>patch))(?P<scope>\(.+\))?(?P<bang>!)?:"
179+
Or with fallback regex: r"^((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):" # First group is type
180+
bump_map: A mapping of commit types to their corresponding version increments.
181+
Example: {
182+
"major": SemVerIncrement.MAJOR,
183+
"bang": SemVerIncrement.MAJOR,
184+
"minor": SemVerIncrement.MINOR,
185+
"patch": SemVerIncrement.PATCH
186+
}
187+
Or with fallback: {
188+
(r"^.+!$", SemVerIncrement.MAJOR),
189+
(r"^BREAKING[\-\ ]CHANGE", SemVerIncrement.MAJOR),
190+
(r"^feat", SemVerIncrement.MINOR),
191+
(r"^fix", SemVerIncrement.PATCH),
192+
(r"^refactor", SemVerIncrement.PATCH),
193+
(r"^perf", SemVerIncrement.PATCH),
194+
}
195+
bump_map_major_version_zero: A mapping of commit types to version increments
196+
specifically for when the major version is 0. This allows for different
197+
versioning behavior during initial development.
198+
The format is the same as bump_map.
199+
Example: {
200+
"major": SemVerIncrement.MINOR, # MAJOR becomes MINOR in version zero
201+
"bang": SemVerIncrement.MINOR, # Breaking changes become MINOR in version zero
202+
"minor": SemVerIncrement.MINOR,
203+
"patch": SemVerIncrement.PATCH
204+
}
205+
Or with fallback: {
206+
(r"^.+!$", SemVerIncrement.MINOR),
207+
(r"^BREAKING[\-\ ]CHANGE", SemVerIncrement.MINOR),
208+
(r"^feat", SemVerIncrement.MINOR),
209+
(r"^fix", SemVerIncrement.PATCH),
210+
(r"^refactor", SemVerIncrement.PATCH),
211+
(r"^perf", SemVerIncrement.PATCH),
212+
}
213+
214+
Raises:
215+
NoPatternMapError: If any of the required parameters are empty or None
216+
"""
168217
if not bump_map or not bump_pattern or not bump_map_major_version_zero:
169218
raise NoPatternMapError(
170219
f"Invalid bump rule: {bump_pattern=} and {bump_map=} and {bump_map_major_version_zero=}"
@@ -194,10 +243,9 @@ def get_increment(
194243
):
195244
return ret
196245
except IndexError:
197-
# Fallback to old school bump rule
198246
pass
199247

200-
# Fallback to old school bump rule
248+
# Fallback to old school bump rule, for backward compatibility
201249
found_keyword = m.group(1)
202250
for match_pattern, increment in effective_bump_map.items():
203251
if re.match(match_pattern, found_keyword):

0 commit comments

Comments
(0)

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