From ae75dd552dd78054310317a4ca5229b83ea9ed4d Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 08:46:20 +0200 Subject: [PATCH 1/7] test: add test for 'additional' types in conventional commits --- tests/test_bump_find_increment.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 32a978556c..22cb42c7b6 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -41,6 +41,12 @@ "fix(setup.py): future is now required for every python version", ] +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 = [ @@ -67,6 +73,7 @@ (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"), (NONE_INCREMENT_CC, None), ), From e37c0a90ef9dab0ced7d922fd9a26b89b50ba3fe Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 09:08:38 +0200 Subject: [PATCH 2/7] fix(bump): breaking changes on additional types for conventional commits --- commitizen/defaults.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index fb117547f8..c8e12780ca 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -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), From 87a5c98d7b3e882bee74cde85b83f47f52f756f1 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 09:27:22 +0200 Subject: [PATCH 3/7] test: add test for 'additional' types in changelog --- tests/commands/test_changelog_command.py | 12 ++++++++++++ ...eaking_change_content_v1_with_exclamation_mark.md | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark.md diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index bdc384c3ca..ceab831269 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -515,6 +515,18 @@ 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_changelog_config_flag_increment( mocker: MockFixture, changelog_path, config_path, file_regression diff --git a/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark.md b/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark.md new file mode 100644 index 0000000000..d12d780dab --- /dev/null +++ b/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark.md @@ -0,0 +1,5 @@ +## Unreleased + + +- drop support for py36 + From 8bfc98dffe221d0598b55272bc9a402cf14add94 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 09:28:09 +0200 Subject: [PATCH 4/7] fix(changelog): breaking change on additional types for conventional commits --- commitizen/defaults.py | 2 +- tests/commands/test_changelog_command.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index c8e12780ca..4948ade45f 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -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"^(?Pfeat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P[^()\r\n]*)\)|\()?(?P!)?:\s(?P.*)?" # noqa +commit_parser = r"^((?Pfeat|fix|refactor|perf|BREAKING CHANGE)(?:\((?P[^()\r\n]*)\)|\()?(?P!)?|\w+!):\s(?P.*)?" # noqa version_parser = r"(?P([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+[0-9A-Za-z-]+)?(\w+)?)" diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index ceab831269..e0931ee166 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -516,7 +516,9 @@ def test_breaking_change_content_v1_multiline( @pytest.mark.usefixtures("tmp_commitizen_project") -def test_breaking_change_content_v1_with_exclamation_mark(mocker: MockFixture, capsys, file_regression): +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"] @@ -527,6 +529,7 @@ def test_breaking_change_content_v1_with_exclamation_mark(mocker: MockFixture, c 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 From c20cb5cc76aba40700c70bcfa945c5c7c99b5d35 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 14:13:57 +0200 Subject: [PATCH 5/7] test(bump): a longer word is used matching a type in commit message --- tests/test_bump_find_increment.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index 22cb42c7b6..d4eb96d8b8 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -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", @@ -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 = [ From 92115055da9456f6e227aab3fc77f198059f3d1e Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 14:14:39 +0200 Subject: [PATCH 6/7] fix(bump): better match for change_type when finding increment Closes #695 --- commitizen/bump.py | 7 +++---- commitizen/defaults.py | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/commitizen/bump.py b/commitizen/bump.py index c405414e87..ed410bbcc1 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -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) @@ -35,8 +34,9 @@ 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): @@ -44,7 +44,7 @@ def find_increment( break if increment == "MAJOR": - continue + break elif increment == "MINOR" and new_increment == "MAJOR": increment = new_increment elif increment == "PATCH" or increment is None: @@ -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 diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 4948ade45f..a7c285edba 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -88,7 +88,7 @@ class Settings(TypedDict, total=False): MINOR = "MINOR" PATCH = "PATCH" -bump_pattern = r"^(((BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?)|\w+!)" +bump_pattern = r"^(((BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?)|\w+!):" bump_map = OrderedDict( ( (r"^.+!$", MAJOR), From 376427c9f219dddbd68061d40c76a8f98c1d38bf Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Fri, 28 Apr 2023 14:26:52 +0200 Subject: [PATCH 7/7] test: add exclamation mark test Closes #682 --- tests/commands/test_changelog_command.py | 15 +++++++++++++++ ...hange_content_v1_with_exclamation_mark_feat.md | 6 ++++++ tests/test_bump_find_increment.py | 5 +++++ 3 files changed, 26 insertions(+) create mode 100644 tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark_feat.md diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index e0931ee166..bb63720839 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -530,6 +530,21 @@ def test_breaking_change_content_v1_with_exclamation_mark( 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 diff --git a/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark_feat.md b/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark_feat.md new file mode 100644 index 0000000000..84c23687c4 --- /dev/null +++ b/tests/commands/test_changelog_command/test_breaking_change_content_v1_with_exclamation_mark_feat.md @@ -0,0 +1,6 @@ +## Unreleased + +### Feat + +- **pipeline**: some text with breaking change + diff --git a/tests/test_bump_find_increment.py b/tests/test_bump_find_increment.py index d4eb96d8b8..337cf17e7a 100644 --- a/tests/test_bump_find_increment.py +++ b/tests/test_bump_find_increment.py @@ -48,6 +48,10 @@ "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", @@ -82,6 +86,7 @@ (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), ), )