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

Fix conventional commits schema pattern #382

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 3 commits into from
May 6, 2021
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
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