Skip to content

Commit 3a7ff2c

Browse files
committed
no-mistakes(document): Document bump_map no-bump rules
1 parent fa667dc commit 3a7ff2c

5 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎commitizen/version_increment.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""Helpers for comparing and deriving semantic-version increments.
2+
3+
This module centralizes the conversion between external increment labels and the
4+
ordered enum used internally by bump-related commands. The distinction matters
5+
because some callers intentionally coerce unknown values to ``NONE`` while
6+
matched ``bump_map`` outputs must preserve the historical fail-fast behavior for
7+
invalid custom rule values.
8+
"""
9+
110
from __future__ import annotations
211

312
import re
@@ -20,6 +29,12 @@ class VersionIncrement(IntEnum):
2029
- PATCH: backwards-compatible bug fixes
2130
- MINOR: backwards-compatible features
2231
- MAJOR: incompatible API changes
32+
33+
Examples:
34+
```python
35+
max([VersionIncrement.PATCH, VersionIncrement.MINOR])
36+
# VersionIncrement.MINOR
37+
```
2338
"""
2439

2540
NONE = 0
@@ -33,7 +48,13 @@ def __str__(self) -> str:
3348

3449
@classmethod
3550
def from_value(cls, value: object) -> VersionIncrement:
36-
"""Convert a possibly-invalid external value into a known increment."""
51+
"""Convert external increment input into a known increment.
52+
53+
This lenient path is used for inputs such as CLI arguments where an
54+
unknown string should behave like "no increment" instead of raising.
55+
Matched ``bump_map`` values are validated separately so custom rules keep
56+
their historical fail-fast behavior.
57+
"""
3758
if not isinstance(value, str):
3859
return VersionIncrement.NONE
3960
try:

‎docs/customization/config_file.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ Example:
160160
| `schema_pattern` | `str` | `""` | (OPTIONAL) The regular expression used to do commit message validation. Used by `cz check`. |
161161
| `info_path` | `str` | `""` | (OPTIONAL) The path to the file that contains explanation of the commit rules. Used by `cz info`. If not provided `cz info`, will load `info` instead. |
162162
| `info` | `str` | `""` | (OPTIONAL) Explanation of the commit rules. Used by `cz info`. |
163-
| `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
163+
| `bump_map` | `dict` | `None` | (OPTIONAL) Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`). In JSON and YAML configs, `null` keeps a matched rule from bumping the version. |
164164
| `bump_pattern` | `str` | `None` | (OPTIONAL) Regex to extract information from commit (subject and body) |
165165
| `change_type_order` | `str` | `None` | (OPTIONAL) List of strings used to order the Changelog. All other types will be sorted alphabetically. Default is `["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]` |
166166
| `commit_parser` | `str` | `None` | (OPTIONAL) Regex to extract information used in creating changelog. [See more][changelog-spec] |

‎docs/customization/python_class.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ You need to define 2 parameters inside your custom `BaseCommitizen`.
9999
| Parameter | Type | Default | Description |
100100
| -------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------- |
101101
| `bump_pattern` | `str` | `None` | Regex to extract information from commit (subject and body) |
102-
| `bump_map` | `dict` | `None` | Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`) |
102+
| `bump_map` | `dict` | `None` | Dictionary mapping the extracted information to a `SemVer` increment type (`MAJOR`, `MINOR`, `PATCH`). Use `None` when a matched rule should not bump the version. |
103103

104104
Let's see an example.
105105

‎tests/commands/test_bump_command.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,7 +1330,6 @@ def test_bump_allow_no_commit_with_no_eligible_commit(
13301330
assert "bump: version 1.0.0 → 1.0.1" in out
13311331

13321332

1333-
13341333
def test_bump_allow_no_commit_with_invalid_custom_bump_map_raises(
13351334
tmp_commitizen_project: Path,
13361335
monkeypatch: pytest.MonkeyPatch,
@@ -1369,7 +1368,6 @@ def test_bump_allow_no_commit_with_invalid_custom_bump_map_raises(
13691368
assert git.tag_exist("0.1.2") is False
13701369

13711370

1372-
13731371
def test_bump_allow_no_commit_with_string_none_bump_map_raises(
13741372
tmp_commitizen_project: Path,
13751373
monkeypatch: pytest.MonkeyPatch,

‎tests/test_version_increment.py‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ def test_get_highest_by_messages_supports_custom_none_mapping() -> None:
221221
)
222222

223223

224-
225224
def test_get_highest_by_messages_rejects_string_none_mapping() -> None:
226225
"""The string NONE remains invalid at the bump-map computation boundary."""
227226
with pytest.raises(ValueError, match="NONE"):
@@ -232,7 +231,6 @@ def test_get_highest_by_messages_rejects_string_none_mapping() -> None:
232231
)
233232

234233

235-
236234
def test_from_message_stops_after_major_match() -> None:
237235
"""A major match on one line shields later invalid lines in that message."""
238236
assert (
@@ -245,7 +243,6 @@ def test_from_message_stops_after_major_match() -> None:
245243
)
246244

247245

248-
249246
def test_get_highest_by_messages_raises_for_invalid_bump_map_value() -> None:
250247
"""A matched custom bump-map value must fail instead of becoming NONE."""
251248
with pytest.raises(ValueError, match="MINORR"):
@@ -256,7 +253,6 @@ def test_get_highest_by_messages_raises_for_invalid_bump_map_value() -> None:
256253
)
257254

258255

259-
260256
def test_get_highest_by_messages_compiles_pattern_once(
261257
monkeypatch: pytest.MonkeyPatch,
262258
) -> None:

0 commit comments

Comments
 (0)