diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 7d5c27570c..6ac62d5ec1 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -178,8 +178,8 @@ def schema(self) -> str: def schema_pattern(self) -> str: PATTERN = ( - r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)!?" - r"(\(\S+\))?:(\s.*)" + r"(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|bump)" + r"(\(\S+\))?!?:(\s.*)" ) return PATTERN diff --git a/tests/commands/test_check_command.py b/tests/commands/test_check_command.py index df54c1234e..ac545e3a6a 100644 --- a/tests/commands/test_check_command.py +++ b/tests/commands/test_check_command.py @@ -124,12 +124,15 @@ def test_check_conventional_commit_succeeds(mocker, capsys): assert "Commit validation: successful!" in out -def test_check_no_conventional_commit(config, mocker, tmpdir): +@pytest.mark.parametrize( + "commit_msg", ("feat!(lang): removed polish language", "no conventional commit",), +) +def test_check_no_conventional_commit(commit_msg, config, mocker, tmpdir): with pytest.raises(InvalidCommitMessageError): error_mock = mocker.patch("commitizen.out.error") tempfile = tmpdir.join("temp_commit_file") - tempfile.write("no conventional commit") + tempfile.write(commit_msg) check_cmd = commands.Check( config=config, arguments={"commit_msg_file": tempfile} @@ -141,6 +144,7 @@ def test_check_no_conventional_commit(config, mocker, tmpdir): @pytest.mark.parametrize( "commit_msg", ( + "feat(lang)!: removed polish language", "feat(lang): added polish language", "feat: add polish language", "bump: 0.0.1 -> 1.0.0", diff --git a/tests/test_cz_conventional_commits.py b/tests/test_cz_conventional_commits.py index 62eef11a19..e43284a121 100644 --- a/tests/test_cz_conventional_commits.py +++ b/tests/test_cz_conventional_commits.py @@ -132,7 +132,15 @@ def test_info(config): assert isinstance(info, str) -def test_process_commit(config): +@pytest.mark.parametrize( + ("commit_message", "expected_message"), + [ + ("test(test_scope): this is test msg", "this is test msg",), + ("test(test_scope)!: this is test msg", "this is test msg",), + ("test!(test_scope): this is test msg", "",), + ], +) +def test_process_commit(commit_message, expected_message, config): conventional_commits = ConventionalCommitsCz(config) - message = conventional_commits.process_commit("test(test_scope): this is test msg") - assert message == "this is test msg" + message = conventional_commits.process_commit(commit_message) + assert message == expected_message