File tree 3 files changed +11
-8
lines changed
3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 1
1
2
2
- id : commit-msg-regex-hook
3
- name : commit-msg-regex-hook
3
+ name : Validate commit message with Regex
4
4
description : Checks if commit message matches the passed in regex
5
5
entry : commit-msg-regex-hook
6
6
language : python
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ First you will need to setup [pre-commit](https://pre-commit.com/) using their d
13
13
rev: v0.3.1
14
14
hooks:
15
15
- id: commit-msg-hook
16
- args: [--pattern='[A-Z]{3,4}-[0-9]{3,6} \\| [\\w\\s]* \\| .+']
16
+ args: [" --pattern='[A-Z]{3,4}-[0-9]{3,6} \\| [\\w\\s]* \\| .+'" ]
17
17
stages: [commit-msg]
18
18
```
19
19
Original file line number Diff line number Diff line change @@ -62,7 +62,6 @@ def main():
62
62
63
63
def process_file (path : str ) -> str :
64
64
"""Extract commit message.
65
- On failure the commit is aborted.
66
65
67
66
Args:
68
67
path (str): The path of the file with commit message
@@ -78,15 +77,19 @@ def process_file(path: str) -> str:
78
77
return msg
79
78
80
79
81
- def process_pattern (pattern_str : str ) -> Pattern :
82
- """Verify regex pattern and return the pattern object
80
+ def process_pattern (str_pattern : str ) -> Pattern :
81
+ """Convert string pattern to regex pattern object.
82
+
83
+ Args:
84
+ pattern_str (str): The path of the file with commit message
85
+ Returns:
86
+ pattern (Pattern): The compiled regex pattern.
83
87
"""
84
88
try :
85
- print (f"Incoming Pattern: { pattern_str } " )
86
- pattern = re .compile (pattern_str [1 :- 1 ])
89
+ pattern = re .compile (str_pattern [1 :- 1 ])
87
90
except Exception as e :
88
91
raise argparse .ArgumentTypeError (
89
- f"'{ pattern_str } ' is not a valid regex pattern\n { e } "
92
+ f"'{ str_pattern } ' is not a valid regex pattern\n { e } "
90
93
)
91
94
92
95
return pattern
You can’t perform that action at this time.
0 commit comments