-
Notifications
You must be signed in to change notification settings - Fork 53
/
test-pr.py
executable file
·52 lines (41 loc) · 1.38 KB
/
test-pr.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
51
52
#!/usr/bin/env python3
import json
import os
import re
import shlex
import sys
import urllib.request
def main():
with open(os.environ['GITHUB_EVENT_PATH']) as f:
event = json.load(f)
url = 'https://api.github.com/repos/{}/pulls/{}/files'.format(
os.environ['GITHUB_REPOSITORY'],
event['pull_request']['number'],
)
r = urllib.request.Request(url, headers={'Accept': 'application/json'})
f = urllib.request.urlopen(r)
files = json.load(f)
files = [x['filename'] for x in files]
addons_changed = []
schema_changed = False
checker_changed = False
for fname in files:
match = re.match(r'^addons/([^/]+)\.json$', fname)
if match and os.path.exists(fname):
addons_changed.append(match.group(1))
elif re.match(r'^schema/.+$', fname):
schema_changed = True
elif fname == 'tools/check-list.py':
checker_changed = True
if schema_changed or checker_changed:
return os.system('./tools/check-list.py')
if len(addons_changed) > 0:
return os.system('./tools/check-list.py {}'.format(
' '.join([shlex.quote(a) for a in addons_changed]))
)
return 0
if __name__ == '__main__':
# Sometimes, check-list.py returns 256. Apparently, sys.exit() will only
# accept 0-255, so we have to adjust. Weird.
if main() > 0:
sys.exit(1)