forked from tjdevries/config_manager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommit-msg
More file actions
executable file
·80 lines (60 loc) · 1.93 KB
/
commit-msg
File metadata and controls
executable file
·80 lines (60 loc) · 1.93 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python3
import sys
from os.path import expanduser
from enchant import DictWithPWL
from enchant.checker import SpellChecker
home = expanduser('~')
my_words = home + '/.my_words.txt'
dict_to_check = DictWithPWL('en_US', my_words)
chkr = SpellChecker(dict_to_check)
def check_line(line):
# Don't check comments
if line[0] == '#':
return 0
error_count = 0
chkr.set_text(line)
for err in chkr:
try:
sys.stdin = open("/dev/tty", "r")
with sys.stdin:
print('Error: `{}`. \n\t1. Error\n\t2. Add to dictionary'.format(err.word))
opt = int(input())
except EOFError:
break
if opt == 1:
error_count += 1
if opt == 2:
with open(my_words, 'a') as f:
f.write(str(err.word) + '\n')
return error_count
def print_msg(message, level=None):
levels = ['Error', 'Info']
if level not in levels:
print(message)
else:
length = max(len(x) for x in levels)
print('[ {l:{length}} ] {m}'.format(l=level, length=length, m=message))
# Create an error counter
error_count = 0
# Find the temporary file
commit_msg_filepath = sys.argv[1]
# Open the file
with open(commit_msg_filepath, 'r') as f:
line = f.readline()
# Check the Commit Subject
if line[0].capitalize() != line[0]:
print_msg('Commit subject must start with a capital letter', 'Error')
error_count += 1
if '.\n' in line or '.' == line[-1]:
print_msg('Commit subject should not end with a period', 'Error')
error_count += 1
if len(line) >= 50:
print_msg('Commit subject must be less than 50 characters', 'Error')
error_count += check_line(line)
for line in f:
error_count += check_line(line)
if error_count:
print_msg('Commit not acceptable', 'Info')
sys.exit(error_count)
else:
print_msg('Commit acceptable', 'Info')