Skip to content

Commit 2eb168e

Browse files
committed
no-mistakes(ci): Fixed PR-caused code issues by restoring the public commitizen.bump.find_increment compatibility shim in commitizen/bump.py, adding focused regression coverage in tests/test_bump_find_increment.py, and protecting the MkDocs snippet block in docs/customization/python_class.md from blacken-docs rewrites so pre-commit/CI formatting passes. Verified with uv run pytest tests/test_bump_find_increment.py tests/commands/test_documented_python_class_examples.py -q, uv run ruff check ..., uv run mypy ..., uv run --no-sync prek run --all-files, uv run --no-sync poe cover, and uv run --no-sync mkdocs build. Note: the full local poe ci sequence still stops at commit-history validation for existing no-mistakes(...) commit subjects, which is a non-file-change issue outside this code fix
1 parent 60c1d6b commit 2eb168e

3 files changed

Lines changed: 66 additions & 3 deletions

File tree

‎commitizen/bump.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@
44
import re
55
from glob import iglob
66
from string import Template
7-
from typing import TYPE_CHECKING
7+
from typing import TYPE_CHECKING, cast
88

99
from commitizen.defaults import BUMP_MESSAGE
1010
from commitizen.exceptions import CurrentVersionNotFoundError
1111
from commitizen.git import smart_open
12+
from commitizen.version_increment import VersionIncrement
1213

1314
if TYPE_CHECKING:
14-
from collections.abc import Generator, Iterable
15+
from collections.abc import Generator, Iterable, Mapping
1516

16-
from commitizen.version_schemes import VersionProtocol
17+
from commitizen.git import GitCommit
18+
from commitizen.version_schemes import Increment, VersionProtocol
19+
20+
21+
def find_increment(
22+
commits: list[GitCommit], regex: str, increments_map: Mapping[str, object]
23+
) -> Increment | None:
24+
"""Preserve the legacy bump helper as a compatibility shim.
25+
26+
This public helper remains available for integrations importing
27+
``commitizen.bump.find_increment`` while delegating the real increment
28+
comparison and extraction logic to ``VersionIncrement``.
29+
"""
30+
increment = VersionIncrement.get_highest_by_messages(
31+
(commit.message for commit in commits),
32+
regex,
33+
increments_map,
34+
)
35+
if increment == VersionIncrement.NONE:
36+
return None
37+
return cast("Increment", str(increment))
1738

1839

1940
def update_version_in_files(

‎docs/customization/python_class.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,11 @@ keeps the example executable while still overriding the bump rules. The module
106106
below is the same file exercised by Commitizen's test suite and type-checked by
107107
mypy.
108108

109+
<!-- blacken-docs:off -->
109110
```python title="cz_docs_only.py"
110111
--8<-- "docs/examples/cz_docs_only.py"
111112
```
113+
<!-- blacken-docs:on -->
112114

113115
Package and install `cz_docs_only.py` just like the earlier `cz_jira.py`
114116
example, and expose it through the same `commitizen.plugin` entry point group,

‎tests/test_bump_find_increment.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Regression tests for the public ``commitizen.bump.find_increment`` helper."""
2+
3+
from commitizen import bump
4+
from commitizen.cz.conventional_commits import ConventionalCommitsCz
5+
from commitizen.git import GitCommit
6+
7+
8+
def test_find_increment_keeps_public_api_behavior() -> None:
9+
"""The compatibility shim still returns the highest named increment."""
10+
# Arrange
11+
commits = [
12+
GitCommit(rev="test", title="fix: correct typo"),
13+
GitCommit(rev="test", title="feat(api): add endpoint"),
14+
]
15+
16+
# Act
17+
increment = bump.find_increment(
18+
commits,
19+
regex=ConventionalCommitsCz.bump_pattern,
20+
increments_map=ConventionalCommitsCz.bump_map,
21+
)
22+
23+
# Assert
24+
assert increment == "MINOR"
25+
26+
27+
def test_find_increment_supports_custom_none_mapping() -> None:
28+
"""A matched custom rule can still opt out of bumping entirely."""
29+
# Arrange
30+
commits = [GitCommit(rev="test", title="docs: expand usage guide")]
31+
32+
# Act
33+
increment = bump.find_increment(
34+
commits,
35+
regex=r"^(docs)",
36+
increments_map={"docs": None},
37+
)
38+
39+
# Assert
40+
assert increment is None

0 commit comments

Comments
 (0)