Skip to content

Commit 07386e7

Browse files
committed
no-mistakes(review): Preserve major short-circuit in multiline bump detection
1 parent c130f3e commit 07386e7

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

‎commitizen/version_increment.py‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,21 @@ def from_message(
9090
This method preserves that behavior while returning a comparable enum.
9191
"""
9292
select_pattern = cls._compile_pattern(regex)
93-
increments = []
93+
increment = cls.NONE
9494

9595
for line in message.split("\n"):
9696
result = select_pattern.search(line)
97-
if result:
98-
increments.append(cls.from_match(result.group(1), increments_map))
97+
if not result:
98+
continue
9999

100-
return max(increments, default=cls.NONE)
100+
increment = max(
101+
increment,
102+
cls.from_match(result.group(1), increments_map),
103+
)
104+
if increment == cls.MAJOR:
105+
return increment
106+
107+
return increment
101108

102109
@classmethod
103110
def get_highest_by_messages(

‎tests/test_version_increment.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ def test_get_highest_by_messages_supports_custom_none_mapping() -> None:
222222

223223

224224

225+
def test_from_message_stops_after_major_match() -> None:
226+
"""A major match on one line shields later invalid lines in that message."""
227+
assert (
228+
VersionIncrement.from_message(
229+
"break: api\n\noops: typo",
230+
r"^(break|oops)",
231+
{"break": "MAJOR", "oops": "MINORR"},
232+
)
233+
== VersionIncrement.MAJOR
234+
)
235+
236+
237+
225238
def test_get_highest_by_messages_raises_for_invalid_bump_map_value() -> None:
226239
"""A matched custom bump-map value must fail instead of becoming NONE."""
227240
with pytest.raises(ValueError, match="MINORR"):

0 commit comments

Comments
 (0)