@@ -97,12 +97,10 @@ def check_subject_uses_imperative(commit_message):
97
97
third_person_blob = TextBlob (third_person_prefix + first_line )
98
98
non_third_person_blob = TextBlob (non_third_person_prefix + first_line )
99
99
100
- first_word , third_person_result = third_person_blob .tags [
101
- words_in_third_person_prefix_blob
102
- ]
103
- _ , non_third_person_result = non_third_person_blob .tags [
104
- words_in_non_third_person_prefix_blob
105
- ]
100
+ tags = third_person_blob .tags
101
+ first_word , third_person_result = tags [words_in_third_person_prefix_blob ]
102
+ tags = non_third_person_blob .tags
103
+ _ , non_third_person_result = tags [words_in_non_third_person_prefix_blob ]
106
104
107
105
# We need to determine whether the first word is a non-third person verb
108
106
# when parsed in a non-third person blob. However, there were some
@@ -167,6 +165,12 @@ def check(
167
165
return all_rules_verified
168
166
169
167
168
+ def strip_prefix (commit_message ):
169
+ if ":" in commit_message :
170
+ return commit_message [commit_message .index (":" ) + 1 :].strip ()
171
+ return commit_message
172
+
173
+
170
174
def main ():
171
175
parser_description = (
172
176
"Bad commit message blocker: Avoid bad commit messages in your repository"
@@ -183,6 +187,13 @@ def main():
183
187
help = "The maximum allowed length for a line in the commit body" ,
184
188
default = DEFAULT_BODY_LIMIT ,
185
189
)
190
+ parser .add_argument (
191
+ "--conventional-commit" ,
192
+ help = "Whether the commit message follows the conventional commit format,"
193
+ " e.g. 'feat: add new feature'" ,
194
+ type = bool ,
195
+ default = False ,
196
+ )
186
197
args = parser .parse_args ()
187
198
188
199
commit_message = args .message .strip ()
@@ -197,6 +208,9 @@ def main():
197
208
+ CliColors .ENDC
198
209
)
199
210
211
+ if args .conventional_commit :
212
+ commit_message = strip_prefix (commit_message )
213
+
200
214
all_rules_verified = check (
201
215
commit_message , int (args .subject_limit ), int (args .body_limit )
202
216
)
0 commit comments