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 fb117547f8..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)(\(.+\))?(!)?" +bump_pattern = r"^(((BREAKING[\-\ ]CHANGE|feat|fix|refactor|perf)(\(.+\))?(!)?)|\w+!):" bump_map = OrderedDict( ( (r"^.+!$", MAJOR), @@ -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 bdc384c3ca..bb63720839 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -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 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 + 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 32a978556c..337cf17e7a 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 = [ @@ -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 = [ @@ -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), ), )