forked from hail-is/hail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
project-changed.py
50 lines (39 loc) · 1.19 KB
/
project-changed.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
import sys
import subprocess
if len(sys.argv) != 3:
sys.stderr.write('''usage: {} <orig-hash> <project>
outputs 'yes' if <project> changed in HEAD compared to <orig-hash> else 'no'.
''', sys.argv[0])
exit(1)
projects = []
with open('projects.txt', 'r') as f:
for line in f:
line = line.strip()
if not line:
continue
projects.append(line)
orig_hash = sys.argv[1]
target_project = sys.argv[2]
if target_project not in projects:
sys.stderr.write('unknown project: {}\n'.format(target_project))
exit(1)
cmd = ['git', 'diff', '--name-only', orig_hash]
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
if proc.returncode != 0:
sys.stderr.write('command exited with return code {}: {}'.format(proc.returncode, ' '.join(cmd)))
exit(1)
def get_project(line):
for project in projects:
if line.startswith(project + '/'):
return project
return None
for line in proc.stdout.decode('utf-8').split('\n'):
line = line.strip()
if not line:
continue
line_project = get_project(line)
if line_project == target_project or line_project is None:
print('yes')
exit(0)
print('no')
exit(0)