@@ -44,14 +44,32 @@ def main():
44
44
Parse passed in regex and verify message matches
45
45
"""
46
46
parser = argparse .ArgumentParser ()
47
- parser .add_argument ("message" , nargs = "?" , type = process_file , default = COMMIT_EDITMSG ,
48
- help = "File path for commit message" )
49
- parser .add_argument ("--pattern" , type = process_pattern )
50
47
parser .add_argument (
51
- '--debug' ,
52
- action = 'store_true' ,
53
- help = 'print debug messages to stdout'
54
- )
48
+ "message" ,
49
+ nargs = "?" ,
50
+ type = process_file ,
51
+ default = COMMIT_EDITMSG ,
52
+ help = "File path for commit message" )
53
+
54
+
55
+ parser .add_argument (
56
+ "--failure_message" ,
57
+ type = str ,
58
+ default = "Commit Message does not match pattern" ,
59
+ help = "The message to display if the commit message doesn't match the Regex" )
60
+
61
+
62
+ parser .add_argument (
63
+ "--pattern" ,
64
+ type = process_pattern ,
65
+ help = "Pattern to check the commit message against" )
66
+
67
+
68
+ parser .add_argument (
69
+ "--debug" ,
70
+ action = "store_true" ,
71
+ help = "Flag to get debugging messages" )
72
+
55
73
56
74
args = parser .parse_args ()
57
75
@@ -60,7 +78,7 @@ def main():
60
78
61
79
checks = [
62
80
message_not_empty (args .message ),
63
- message_pattern_match (args .message , args .pattern )
81
+ message_pattern_match (args .message , args .pattern , args . failure_message )
64
82
]
65
83
66
84
run_checks (checks )
@@ -130,15 +148,17 @@ def check():
130
148
return check
131
149
132
150
133
- def message_pattern_match (message : str , pattern : Pattern ) -> Result :
151
+ def message_pattern_match (message : str , pattern : Pattern , failure_message : str ) -> Result :
134
152
"""Verify the commit message matches the pattern
135
153
"""
136
154
def check ():
137
155
logger .debug ("Pattern: {regex}\n Message: {message}" , regex = pattern , message = message )
138
156
139
157
if not pattern .match (message ):
140
158
# Fail the commit message
141
- return Result (f"Commit Message does not match pattern\n \t { pattern } \n \t { message } " , FAIL )
159
+ return Result (f"""{ failure_message } \n \t
160
+ Pattern: { pattern } \n \t
161
+ Message: { message } """ , FAIL )
142
162
143
163
return Result ("The commit message matches the regex" , PASS )
144
164
return check
0 commit comments