-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr_has_label.py
executable file
·37 lines (28 loc) · 942 Bytes
/
pr_has_label.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
#!/usr/bin/env python3
import sys
import json
from urllib.request import urlopen # using urllib since it is a standard module (vs. requests)
from urllib.error import URLError
import argparse
parser = argparse.ArgumentParser(description='Determines if a pull request has a defined label')
parser.add_argument('pull_request', type=str,
help='pull request id')
parser.add_argument('label', type=int,
help='label ID')
args = parser.parse_args()
if args.pull_request == 'false':
print("false")
sys.exit(1)
url = "https://api.github.com/repos/qgis/QGIS/pulls/{}".format(args.pull_request)
try:
data = urlopen(url).read().decode('utf-8')
except URLError as err:
print("URLError: {}".format(err.reason))
sys.exit(1)
obj = json.loads(data)
for label in obj['labels']:
if label["id"] == args.label:
print("true")
sys.exit(0)
print("label not found")
sys.exit(1)