Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1dee41e

Browse files
josixLee-W
authored andcommitted
feat(cz_check): Add rev to all displayed ill-formatted commits
* Update _get_commit_messages to get_commits with rev and msg info
1 parent 94f8ae0 commit 1dee41e

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

‎commitizen/commands/check.py‎

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,33 +45,43 @@ def __call__(self):
4545
Raises:
4646
InvalidCommitMessageError: if the commit provided not follows the conventional pattern
4747
"""
48-
commit_msgs = self._get_commit_messages()
49-
if not commit_msgs:
48+
commits = self._get_commits()
49+
if not commits:
5050
raise NoCommitsFoundError(f"No commit found with range: '{self.rev_range}'")
5151

5252
pattern = self.cz.schema_pattern()
53-
ill_formated_commits = []
54-
for commit_msg in commit_msgs:
55-
if not Check.validate_commit_message(commit_msg, pattern):
56-
ill_formated_commits.append(f"commit: {commit_msg}\n")
57-
if ill_formated_commits != []:
53+
ill_formated_commits = [
54+
commit
55+
for commit in commits
56+
if not Check.validate_commit_message(commit["msg"], pattern)
57+
]
58+
displayed_msgs_content = "".join(
59+
[
60+
f"commit {commit['rev'] or ''}: {commit['msg']}\n"
61+
for commit in ill_formated_commits
62+
]
63+
)
64+
if displayed_msgs_content:
5865
raise InvalidCommitMessageError(
5966
"commit validation: failed!\n"
6067
"please enter a commit message in the commitizen format.\n"
61-
f"{''.join(ill_formated_commits)}\n"
68+
f"{displayed_msgs_content}\n"
6269
f"pattern: {pattern}"
6370
)
6471
out.success("Commit validation: successful!")
6572

66-
def _get_commit_messages(self):
73+
def _get_commits(self):
6774
# Get commit message from file (--commit-msg-file)
6875
if self.commit_msg_file:
6976
with open(self.commit_msg_file, "r") as commit_file:
7077
commit_msg = commit_file.read()
71-
return [commit_msg]
78+
return [{"rev": None, "msg": commit_msg}]
7279

7380
# Get commit messages from git log (--rev-range)
74-
return [commit.message for commit in git.get_commits(end=self.rev_range)]
81+
return [
82+
{"rev": commit.rev[:8], "msg": commit.message}
83+
for commit in git.get_commits(end=self.rev_range)
84+
]
7585

7686
@staticmethod
7787
def validate_commit_message(commit_msg: str, pattern: str) -> bool:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /