Skip to content

Commit d52b465

Browse files
authored
Merge pull request #144 from Lee-W/hotfix
Hotfix for version bumping
2 parents 2803b18 + 6d89df3 commit d52b465

File tree

3 files changed

+39
-56
lines changed

3 files changed

+39
-56
lines changed

commitizen/bump.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def find_increment(
3434
continue
3535
found_keyword = result.group(0)
3636
new_increment = increments_map_default[found_keyword]
37-
if new_increment == "MAJOR":
38-
increment = new_increment
39-
break
40-
elif increment == "MINOR" and new_increment == "PATCH":
37+
if increment == "MAJOR":
4138
continue
42-
increment = new_increment
39+
elif increment == "MINOR" and new_increment == "MAJOR":
40+
increment = new_increment
41+
elif increment == "PATCH" or increment is None:
42+
increment = new_increment
4343

4444
return increment
4545

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ git-cz = "commitizen.cli:main"
8989
'if 0:',
9090
'if __name__ == .__main__.:'
9191
]
92+
omit = [
93+
'env/*',
94+
'venv/*',
95+
'*/virtualenv/*',
96+
'*/virtualenvs/*',
97+
'*/tests/*'
98+
]
9299

93100
[build-system]
94101
requires = ["poetry>=0.12"]

tests/test_bump_find_increment.py

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
CC: Conventional commits
33
SVE: Semantic version at the end
44
"""
5+
import pytest
6+
57
from commitizen import bump
68
from commitizen.git import GitCommit
79

810
NONE_INCREMENT_CC = ["docs(README): motivation", "ci: added travis"]
911

1012
PATCH_INCREMENTS_CC = [
11-
"docs(README): motivation",
1213
"fix(setup.py): future is now required for every python version",
14+
"docs(README): motivation",
1315
]
1416

1517
MINOR_INCREMENTS_CC = [
@@ -21,8 +23,8 @@
2123
MAJOR_INCREMENTS_CC = [
2224
"feat(cli): added version",
2325
"docs(README): motivation",
24-
"fix(setup.py): future is now required for every python version",
2526
"BREAKING CHANGE: `extends` key in config file is now used for extending other config files", # noqa
27+
"fix(setup.py): future is now required for every python version",
2628
]
2729

2830
PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"]
@@ -44,58 +46,32 @@
4446
semantic_version_map = {"MAJOR": "MAJOR", "MINOR": "MINOR", "PATCH": "PATCH"}
4547

4648

47-
def test_find_increment_type_patch():
48-
messages = PATCH_INCREMENTS_CC
49-
commits = [GitCommit(rev="test", title=message) for message in messages]
50-
increment_type = bump.find_increment(commits)
51-
assert increment_type == "PATCH"
52-
53-
54-
def test_find_increment_type_minor():
55-
messages = MINOR_INCREMENTS_CC
49+
@pytest.mark.parametrize(
50+
"messages, expected_type",
51+
(
52+
(PATCH_INCREMENTS_CC, "PATCH"),
53+
(MINOR_INCREMENTS_CC, "MINOR"),
54+
(MAJOR_INCREMENTS_CC, "MAJOR"),
55+
(NONE_INCREMENT_CC, None),
56+
),
57+
)
58+
def test_find_increment(messages, expected_type):
5659
commits = [GitCommit(rev="test", title=message) for message in messages]
5760
increment_type = bump.find_increment(commits)
58-
assert increment_type == "MINOR"
59-
60-
61-
def test_find_increment_type_major():
62-
messages = MAJOR_INCREMENTS_CC
63-
commits = [GitCommit(rev="test", title=message) for message in messages]
64-
increment_type = bump.find_increment(commits)
65-
assert increment_type == "MAJOR"
66-
67-
68-
def test_find_increment_type_patch_sve():
69-
messages = PATCH_INCREMENTS_SVE
70-
commits = [GitCommit(rev="test", title=message) for message in messages]
71-
increment_type = bump.find_increment(
72-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
73-
)
74-
assert increment_type == "PATCH"
75-
76-
77-
def test_find_increment_type_minor_sve():
78-
messages = MINOR_INCREMENTS_SVE
79-
commits = [GitCommit(rev="test", title=message) for message in messages]
80-
increment_type = bump.find_increment(
81-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
82-
)
83-
assert increment_type == "MINOR"
84-
85-
86-
def test_find_increment_type_major_sve():
87-
messages = MAJOR_INCREMENTS_SVE
88-
commits = [GitCommit(rev="test", title=message) for message in messages]
89-
increment_type = bump.find_increment(
90-
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
91-
)
92-
assert increment_type == "MAJOR"
93-
94-
95-
def test_find_increment_type_none():
96-
messages = NONE_INCREMENT_CC
61+
assert increment_type == expected_type
62+
63+
64+
@pytest.mark.parametrize(
65+
"messages, expected_type",
66+
(
67+
(PATCH_INCREMENTS_SVE, "PATCH"),
68+
(MINOR_INCREMENTS_SVE, "MINOR"),
69+
(MAJOR_INCREMENTS_SVE, "MAJOR"),
70+
),
71+
)
72+
def test_find_increment_sve(messages, expected_type):
9773
commits = [GitCommit(rev="test", title=message) for message in messages]
9874
increment_type = bump.find_increment(
9975
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
10076
)
101-
assert increment_type is None
77+
assert increment_type == expected_type

0 commit comments

Comments
 (0)