-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-msg.py
executable file
·50 lines (39 loc) · 1.18 KB
/
commit-msg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python3
import re
import sys
COMMIT_MESSAGE_REGEX = (
r'^((revert: ")?(feat|fix|docs|style|refactor|perf|test|ci|build|chore)'
r"(\(.*\))?!?:\s.{1,50})"
)
def valid_commit_message(message: str) -> bool:
"""
Function to validate the commit message
Args:
message (str): The message to validate
Returns:
bool: True for valid messages, False otherwise
"""
if not re.match(COMMIT_MESSAGE_REGEX, message):
print(
"Proper commit message format is required for automated changelog"
"generation. Examples:\n\n"
)
print("feat(compiler): add 'comments' option")
print("fix(v-model): handle events on blur (close #28)\n\n")
print("See Conventional Commits for more details.\n")
return False
print("Commit message is valid.")
return True
def main() -> None:
"""Main function."""
message_file = sys.argv[1]
try:
txt_file = open(message_file, "r")
commit_message = txt_file.read()
finally:
txt_file.close()
if not valid_commit_message(commit_message):
sys.exit(1)
sys.exit(0)
if __name__ == "__main__":
main()