@@ -79,20 +79,19 @@ def __call__(self) -> None:
79
79
if not commits :
80
80
raise NoCommitsFoundError (f"No commit found with range: '{ self .rev_range } '" )
81
81
82
- pattern = self .cz .schema_pattern ()
83
- displayed_msgs_content = "\n " .join (
84
- [
85
- f'commit "{ commit .rev } ": "{ commit .message } "'
86
- for commit in commits
87
- if not self .validate_commit_message (commit .message , pattern )
88
- ]
82
+ pattern = re .compile (self .cz .schema_pattern ())
83
+ invalid_msgs_content = "\n " .join (
84
+ f'commit "{ commit .rev } ": "{ commit .message } "'
85
+ for commit in commits
86
+ if not self ._validate_commit_message (commit .message , pattern )
89
87
)
90
- if displayed_msgs_content :
88
+ if invalid_msgs_content :
89
+ # TODO: capitalize the first letter of the error message for consistency in v5
91
90
raise InvalidCommitMessageError (
92
91
"commit validation: failed!\n "
93
92
"please enter a commit message in the commitizen format.\n "
94
- f"{ displayed_msgs_content } \n "
95
- f"pattern: { pattern } "
93
+ f"{ invalid_msgs_content } \n "
94
+ f"pattern: { pattern . pattern } "
96
95
)
97
96
out .success ("Commit validation: successful!" )
98
97
@@ -143,14 +142,18 @@ def _filter_comments(msg: str) -> str:
143
142
lines .append (line )
144
143
return "\n " .join (lines )
145
144
146
- def validate_commit_message (self , commit_msg : str , pattern : str ) -> bool :
145
+ def _validate_commit_message (
146
+ self , commit_msg : str , pattern : re .Pattern [str ]
147
+ ) -> bool :
147
148
if not commit_msg :
148
149
return self .allow_abort
149
150
150
151
if any (map (commit_msg .startswith , self .allowed_prefixes )):
151
152
return True
153
+
152
154
if self .max_msg_length :
153
155
msg_len = len (commit_msg .partition ("\n " )[0 ].strip ())
154
156
if msg_len > self .max_msg_length :
155
157
return False
156
- return bool (re .match (pattern , commit_msg ))
158
+
159
+ return bool (pattern .match (commit_msg ))
0 commit comments