Skip to content

Commit

Permalink
Merge pull request #382 from shifqu/fix-convetional-commits-schema-pa…
Browse files Browse the repository at this point in the history
…ttern

Fix conventional commits schema pattern
  • Loading branch information
woile authored May 6, 2021
2 parents 6082b64 + e107411 commit 5d8bc74
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions commitizen/cz/conventional_commits/conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions tests/commands/test_check_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions tests/test_cz_conventional_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5d8bc74

Please sign in to comment.