@@ -45,33 +45,43 @@ def __call__(self):
45
45
Raises:
46
46
InvalidCommitMessageError: if the commit provided not follows the conventional pattern
47
47
"""
48
- commit_msgs = self ._get_commit_messages ()
49
- if not commit_msgs :
48
+ commits = self ._get_commits ()
49
+ if not commits :
50
50
raise NoCommitsFoundError (f"No commit found with range: '{ self .rev_range } '" )
51
51
52
52
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 :
58
65
raise InvalidCommitMessageError (
59
66
"commit validation: failed!\n "
60
67
"please enter a commit message in the commitizen format.\n "
61
- f"{ '' . join ( ill_formated_commits ) } \n "
68
+ f"{ displayed_msgs_content } \n "
62
69
f"pattern: { pattern } "
63
70
)
64
71
out .success ("Commit validation: successful!" )
65
72
66
- def _get_commit_messages (self ):
73
+ def _get_commits (self ):
67
74
# Get commit message from file (--commit-msg-file)
68
75
if self .commit_msg_file :
69
76
with open (self .commit_msg_file , "r" ) as commit_file :
70
77
commit_msg = commit_file .read ()
71
- return [commit_msg ]
78
+ return [{ "rev" : None , "msg" : commit_msg } ]
72
79
73
80
# 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
+ ]
75
85
76
86
@staticmethod
77
87
def validate_commit_message (commit_msg : str , pattern : str ) -> bool :
0 commit comments