Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def find_increment(
continue
found_keyword = result.group(0)
new_increment = increments_map_default[found_keyword]
if new_increment == "MAJOR":
increment = new_increment
break
elif increment == "MINOR" and new_increment == "PATCH":
if increment == "MAJOR":
continue
increment = new_increment
elif increment == "MINOR" and new_increment == "MAJOR":
increment = new_increment
elif increment == "PATCH" or increment is None:
increment = new_increment

return increment

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ git-cz = "commitizen.cli:main"
'if 0:',
'if __name__ == .__main__.:'
]
omit = [
'env/*',
'venv/*',
'*/virtualenv/*',
'*/virtualenvs/*',
'*/tests/*'
]

[build-system]
requires = ["poetry>=0.12"]
Expand Down
78 changes: 27 additions & 51 deletions tests/test_bump_find_increment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
CC: Conventional commits
SVE: Semantic version at the end
"""
import pytest

from commitizen import bump
from commitizen.git import GitCommit

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

PATCH_INCREMENTS_CC = [
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
"docs(README): motivation",
]

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

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


def test_find_increment_type_patch():
messages = PATCH_INCREMENTS_CC
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(commits)
assert increment_type == "PATCH"


def test_find_increment_type_minor():
messages = MINOR_INCREMENTS_CC
@pytest.mark.parametrize(
"messages, expected_type",
(
(PATCH_INCREMENTS_CC, "PATCH"),
(MINOR_INCREMENTS_CC, "MINOR"),
(MAJOR_INCREMENTS_CC, "MAJOR"),
(NONE_INCREMENT_CC, None),
),
)
def test_find_increment(messages, expected_type):
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(commits)
assert increment_type == "MINOR"


def test_find_increment_type_major():
messages = MAJOR_INCREMENTS_CC
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(commits)
assert increment_type == "MAJOR"


def test_find_increment_type_patch_sve():
messages = PATCH_INCREMENTS_SVE
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
)
assert increment_type == "PATCH"


def test_find_increment_type_minor_sve():
messages = MINOR_INCREMENTS_SVE
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
)
assert increment_type == "MINOR"


def test_find_increment_type_major_sve():
messages = MAJOR_INCREMENTS_SVE
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
)
assert increment_type == "MAJOR"


def test_find_increment_type_none():
messages = NONE_INCREMENT_CC
assert increment_type == expected_type


@pytest.mark.parametrize(
"messages, expected_type",
(
(PATCH_INCREMENTS_SVE, "PATCH"),
(MINOR_INCREMENTS_SVE, "MINOR"),
(MAJOR_INCREMENTS_SVE, "MAJOR"),
),
)
def test_find_increment_sve(messages, expected_type):
commits = [GitCommit(rev="test", title=message) for message in messages]
increment_type = bump.find_increment(
commits, regex=semantic_version_pattern, increments_map=semantic_version_map
)
assert increment_type is None
assert increment_type == expected_type