-
Notifications
You must be signed in to change notification settings - Fork 56
/
pre-commit
executable file
·48 lines (40 loc) · 1.83 KB
/
pre-commit
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
#!/usr/bin/python
from __future__ import print_function
from automation_tools import get_branchname, run_pylint, get_author
from hooksettings import requires_pylint_pass
import subprocess, os, sys
if __name__ == '__main__':
branchname = get_branchname()
if branchname in requires_pylint_pass:
# Compare current pylint score against that in pylint/config.yml
passes = run_pylint(['./lint.py', '--score'])
sys.exit(int(passes))
'''
subprocess.call(['git', 'checkout', 'HEAD', '--', 'hooks/etc/permissions.yml'])
subprocess.call(['git', 'reset', 'HEAD', 'hooks/etc/permissions.yml'])
subprocess.call(['git', 'fetch'])
SHA = subprocess.check_output(['git', 'rev-parse', 'origin/%s' % branchname]).decode('utf-8')
SHA = SHA.replace('\n', '')
print('Getting update permissions file from SHA:(%s)' % SHA)
# Force update the permissions file!
# git checkout -m <revision> <yourfilepath>
subprocess.call(['git', 'checkout', '--theirs', SHA, 'hooks/etc/permissions.yml'])
subprocess.call(['git', 'add', 'hooks/etc/permissions.yml'])
subprocess.call(['git', 'commit', '--no-verify', 'hooks/etc/permissions.yml',
'-m', '"Update permissions"'])
# Check branch permissions
#LOAD PERMISSIONS
allowed = permissions[branchname]
if allowed != 'all' and 'all' not in allowed:
print('(%s) are allowed to commit to current branch %s' % (', '.join(allowed), branchname))
author, _ = get_author()
print('You are: %s' % author)
if author in allowed:
print('Please continue..')
else:
print('You don\'t have correct permissions on %s' % branchname)
sys.exit(1)
else:
print('No permissions restrictions on %s' % branchname)
'''
sys.exit(0)