Skip to content

Commit d82dd5a

Browse files
committed
feat: add ignore_bump_sha_list and ignore_bump_author_list to find_increment
1 parent 573ffda commit d82dd5a

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

commitizen/bump.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424

2525
def find_increment(
26-
commits: list[GitCommit], regex: str, increments_map: dict | OrderedDict
26+
commits: list[GitCommit],
27+
regex: str,
28+
increments_map: dict | OrderedDict,
29+
ignore_bump_sha_list: list[str] | None = None,
30+
ignore_bump_author_list: list[str] | None = None,
2731
) -> Increment | None:
2832
if isinstance(increments_map, dict):
2933
increments_map = OrderedDict(increments_map)
@@ -34,6 +38,18 @@ def find_increment(
3438
increment: str | None = None
3539

3640
for commit in commits:
41+
if ignore_bump_sha_list and commit.rev in ignore_bump_sha_list:
42+
logger.debug(
43+
f"Skipping commit {commit.rev} as it's in ignore_bump_sha_list"
44+
)
45+
continue
46+
47+
if ignore_bump_author_list and commit.author in ignore_bump_author_list:
48+
logger.debug(
49+
f"Skipping commit {commit.rev} as its author '{commit.author}' is in ignore_bump_author_list"
50+
)
51+
continue
52+
3753
for message in commit.message.split("\n"):
3854
result = select_pattern.search(message)
3955

commitizen/commands/bump.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,11 @@ def _find_increment(self, commits: list[git.GitCommit]) -> Increment | None:
158158
raise NoPatternMapError(
159159
f"'{self.config.settings['name']}' rule does not support bump"
160160
)
161-
return bump.find_increment(commits, regex=bump_pattern, increments_map=bump_map)
161+
return bump.find_increment(
162+
commits,
163+
regex=bump_pattern,
164+
increments_map=bump_map,
165+
)
162166

163167
def _validate_arguments(self, current_version: VersionProtocol) -> None:
164168
errors: list[str] = []
@@ -363,6 +367,9 @@ def __call__(self) -> None:
363367
new_tag_version=new_tag_version,
364368
message=message,
365369
increment=increment,
370+
changelog_file_name=(
371+
changelog_cmd.file_name if self.changelog_flag else None
372+
),
366373
changelog_file_name=changelog_file_name,
367374
)
368375

@@ -426,7 +433,9 @@ def __call__(self) -> None:
426433
current_tag_version=new_tag_version,
427434
message=message,
428435
increment=increment,
429-
changelog_file_name=changelog_file_name,
436+
changelog_file_name=(
437+
changelog_cmd.file_name if self.changelog_flag else None
438+
),
430439
)
431440

432441
# TODO: For v3 output this only as diagnostic and remove this if

tests/test_bump_find_increment.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,42 @@ def test_find_increment(messages, expected_type):
108108
assert increment_type == expected_type
109109

110110

111+
def test_find_increment_with_ignored_sha():
112+
messages = [
113+
"docs(README): motivation",
114+
"BREAKING CHANGE: your upstream dependency have some breaking changes",
115+
]
116+
commits = [
117+
GitCommit(rev="test1", title=messages[0]),
118+
GitCommit(rev="test2", title=messages[1]),
119+
]
120+
increment_type = bump.find_increment(
121+
commits,
122+
regex=ConventionalCommitsCz.bump_pattern,
123+
increments_map=ConventionalCommitsCz.bump_map,
124+
ignore_bump_sha_list=["test2"],
125+
)
126+
assert increment_type is None
127+
128+
129+
def test_find_increment_with_ignored_author():
130+
messages = [
131+
"BREAKING CHANGE: your upstream dependency have some breaking changes",
132+
"docs(README): motivation",
133+
]
134+
commits = [
135+
GitCommit(rev="test1", title=messages[0], author="alice"),
136+
GitCommit(rev="test2", title=messages[1], author="bob"),
137+
]
138+
increment_type = bump.find_increment(
139+
commits,
140+
regex=ConventionalCommitsCz.bump_pattern,
141+
increments_map=ConventionalCommitsCz.bump_map,
142+
ignore_bump_author_list=["alice"],
143+
)
144+
assert increment_type is None
145+
146+
111147
@pytest.mark.parametrize(
112148
("messages", "expected_type"),
113149
[

0 commit comments

Comments
 (0)