Skip to content

Commit eac0d6f

Browse files
committed
refactor(check): capitalize error message, rename variable
1 parent a3919c9 commit eac0d6f

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

commitizen/commands/check.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@ def __call__(self):
7272
raise NoCommitsFoundError(f"No commit found with range: '{self.rev_range}'")
7373

7474
pattern = self.cz.schema_pattern()
75-
displayed_msgs_content = "\n".join(
76-
[
77-
f'commit "{commit.rev}": "{commit.message}"'
78-
for commit in commits
79-
if not self.validate_commit_message(commit.message, pattern)
80-
]
75+
invalid_msgs_content = "\n".join(
76+
f'commit "{commit.rev}": "{commit.message}"'
77+
for commit in commits
78+
if not self._validate_commit_message(commit.message, pattern)
8179
)
82-
if displayed_msgs_content:
80+
if invalid_msgs_content:
8381
raise InvalidCommitMessageError(
84-
"commit validation: failed!\n"
85-
"please enter a commit message in the commitizen format.\n"
86-
f"{displayed_msgs_content}\n"
87-
f"pattern: {pattern}"
82+
"Commit validation: failed!\n"
83+
"Please enter a commit message in the commitizen format.\n"
84+
f"{invalid_msgs_content}\n"
85+
f"Pattern: {pattern}"
8886
)
8987
out.success("Commit validation: successful!")
9088

@@ -135,14 +133,16 @@ def _filter_comments(msg: str) -> str:
135133
lines.append(line)
136134
return "\n".join(lines)
137135

138-
def validate_commit_message(self, commit_msg: str, pattern: str) -> bool:
136+
def _validate_commit_message(self, commit_msg: str, pattern: str) -> bool:
139137
if not commit_msg:
140138
return self.allow_abort
141139

142140
if any(map(commit_msg.startswith, self.allowed_prefixes)):
143141
return True
142+
144143
if self.max_msg_length:
145144
msg_len = len(commit_msg.partition("\n")[0].strip())
146145
if msg_len > self.max_msg_length:
147146
return False
147+
148148
return bool(re.match(pattern, commit_msg))

tests/commands/test_check_command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def test_check_command_with_pipe_message_and_failed(mocker: MockFixture):
362362

363363
with pytest.raises(InvalidCommitMessageError) as excinfo:
364364
cli.main()
365-
assert "commit validation: failed!" in str(excinfo.value)
365+
assert "Commit validation: failed!" in str(excinfo.value)
366366

367367

368368
def test_check_command_with_comment_in_message_file(mocker: MockFixture, capsys):

0 commit comments

Comments
 (0)