@@ -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