2019-03-27 09:45:34 -05:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2024-12-01 08:15:14 +01:00
|
|
|
import argparse
|
2019-03-27 09:45:34 -05:00
|
|
|
import json
|
2024-12-01 08:15:14 +01:00
|
|
|
import sys
|
|
|
|
|
2019-03-27 09:45:34 -05:00
|
|
|
from urllib.error import URLError
|
2024-12-01 08:15:14 +01:00
|
|
|
from urllib.request import ( # using urllib since it is a standard module (vs. requests)
|
|
|
|
urlopen,
|
|
|
|
)
|
2019-03-27 09:45:34 -05:00
|
|
|
|
2024-12-01 08:15:14 +01:00
|
|
|
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")
|
2019-03-27 09:45:34 -05:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
2024-12-01 08:15:14 +01:00
|
|
|
if args.pull_request == "false":
|
2019-11-15 17:08:02 +01:00
|
|
|
print("false")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2024-12-01 08:15:14 +01:00
|
|
|
url = f"https://api.github.com/repos/qgis/QGIS/pulls/{args.pull_request}"
|
2019-03-27 09:45:34 -05:00
|
|
|
|
|
|
|
try:
|
2024-12-01 08:15:14 +01:00
|
|
|
data = urlopen(url).read().decode("utf-8")
|
2019-03-27 09:45:34 -05:00
|
|
|
except URLError as err:
|
2024-12-01 08:15:14 +01:00
|
|
|
print(f"URLError: {err.reason}")
|
2019-03-27 09:45:34 -05:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
obj = json.loads(data)
|
|
|
|
|
2024-12-01 08:15:14 +01:00
|
|
|
for label in obj["labels"]:
|
2019-03-27 09:45:34 -05:00
|
|
|
if label["id"] == args.label:
|
|
|
|
print("true")
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
print("label not found")
|
|
|
|
sys.exit(1)
|