Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

test: add test for 'additional' types in conventional commits #728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 1, 2023
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
7 changes: 3 additions & 4 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
def find_increment(
commits: List[GitCommit], regex: str, increments_map: Union[dict, OrderedDict]
) -> Optional[str]:

if isinstance(increments_map, dict):
increments_map = OrderedDict(increments_map)

Expand All @@ -35,16 +34,17 @@ def find_increment(
for commit in commits:
for message in commit.message.split("\n"):
result = select_pattern.search(message)

if result:
found_keyword = result.group(0)
found_keyword = result.group(1)
new_increment = None
for match_pattern in increments_map.keys():
if re.match(match_pattern, found_keyword):
new_increment = increments_map[match_pattern]
break

if increment == "MAJOR":
continue
break
elif increment == "MINOR" and new_increment == "MAJOR":
increment = new_increment
elif increment == "PATCH" or increment is None:
Expand Down Expand Up @@ -103,7 +103,6 @@ def semver_generator(current_version: str, increment: str = None) -> str:
# so it doesn't matter the increment.
# Example: 1.0.0a0 with PATCH/MINOR -> 1.0.0
if not version.is_prerelease:

if increment == MAJOR:
increments_version[MAJOR] += 1
increments_version[MINOR] = 0
Expand Down
4 changes: 2 additions & 2 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class Settings(TypedDict, total=False):
MINOR = "MINOR"
PATCH = "PATCH"

bump_pattern = r"^(BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?"
bump_pattern = r"^(((BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?)|\w+!):"
bump_map = OrderedDict(
(
(r"^.+!$", MAJOR),
Expand All @@ -112,5 +112,5 @@ class Settings(TypedDict, total=False):
change_type_order = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]
bump_message = "bump: version $current_version → $new_version"

commit_parser = r"^(?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?:\s(?P<message>.*)?" # noqa
commit_parser = r"^((?P<change_type>feat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P<scope>[^()\r\n]*)\)|\()?(?P<breaking>!)?|\w+!):\s(?P<message>.*)?" # noqa
version_parser = r"(?P<version>([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)"
30 changes: 30 additions & 0 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,36 @@ def test_breaking_change_content_v1_multiline(
file_regression.check(out, extension=".md")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_breaking_change_content_v1_with_exclamation_mark(
mocker: MockFixture, capsys, file_regression
):
commit_message = "chore!: drop support for py36"
create_file_and_commit(commit_message)
testargs = ["cz", "changelog", "--dry-run"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(DryRunExit):
cli.main()
out, _ = capsys.readouterr()

file_regression.check(out, extension=".md")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_breaking_change_content_v1_with_exclamation_mark_feat(
mocker: MockFixture, capsys, file_regression
):
commit_message = "feat(pipeline)!: some text with breaking change"
create_file_and_commit(commit_message)
testargs = ["cz", "changelog", "--dry-run"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(DryRunExit):
cli.main()
out, _ = capsys.readouterr()

file_regression.check(out, extension=".md")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_changelog_config_flag_increment(
mocker: MockFixture, changelog_path, config_path, file_regression
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Unreleased


- drop support for py36

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this @Lee-W @jenstroeger ?

It won't show the title ### BREAKING CHANGE. But it's the best I could do with the new regex, I cannot repeat the breaking group in here:

https://github.com/commitizen-tools/commitizen/pull/728/files#diff-c951de16d627d82e01eb3ce8d7c4f0b28973ffe147520620762e7140ede2dd80R115

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Unreleased

### Feat

- **pipeline**: some text with breaking change

21 changes: 20 additions & 1 deletion tests/test_bump_find_increment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from commitizen.cz.conventional_commits import ConventionalCommitsCz
from commitizen.git import GitCommit

NONE_INCREMENT_CC = ["docs(README): motivation", "ci: added travis"]
NONE_INCREMENT_CC = [
"docs(README): motivation",
"ci: added travis",
"performance. Remove or disable the reimplemented linters",
"refactor that how this line starts",
]

PATCH_INCREMENTS_CC = [
"fix(setup.py): future is now required for every python version",
Expand All @@ -19,6 +24,8 @@
"feat(cli): added version",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
"perf: app is much faster",
"refactor: app is much faster",
]

MAJOR_INCREMENTS_BREAKING_CHANGE_CC = [
Expand All @@ -41,6 +48,16 @@
"fix(setup.py): future is now required for every python version",
]

MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2 = [
"feat(pipeline)!: some text with breaking change"
]

MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC = [
"chore!: drop support for Python 3.9",
"docs(README): motivation",
"fix(setup.py): future is now required for every python version",
]

PATCH_INCREMENTS_SVE = ["readme motivation PATCH", "fix setup.py PATCH"]

MINOR_INCREMENTS_SVE = [
Expand All @@ -67,7 +84,9 @@
(MINOR_INCREMENTS_CC, "MINOR"),
(MAJOR_INCREMENTS_BREAKING_CHANGE_CC, "MAJOR"),
(MAJOR_INCREMENTS_BREAKING_CHANGE_ALT_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_OTHER_TYPE_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_CC, "MAJOR"),
(MAJOR_INCREMENTS_EXCLAMATION_CC_SAMPLE_2, "MAJOR"),
(NONE_INCREMENT_CC, None),
),
)
Expand Down