-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviews.py
43 lines (36 loc) · 1.43 KB
/
views.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
import requests
from django.conf import settings
from django.http.response import HttpResponse
from django.views.generic.base import View
PRODUCTS_TO_URL = {
"website": "pennlabs.org/",
"platform": "platform.pennlabs.org/",
"penn-clubs": "pennclubs.com/",
}
class PullsView(View):
"""
Returns a view displaying all PRs that have the feature-branch tag and
their status.
"""
def get(self, request):
headers = {"Authorization": settings.GH_PERSONAL_ACCESS_TOKEN}
pulls = []
for product, product_url in PRODUCTS_TO_URL.items():
url = f"https://api.github.com/repos/pennlabs/{product}/pulls"
r = requests.get(url, headers=headers)
if r.status_code != 200:
print(f"Error: Request returned status code {r.status_code}")
return
for pull in r.json():
if "labels" not in pull:
continue
for label in pull["labels"]:
if "name" in label and label["name"].startswith("feature-branch:"):
pulls.append(
{
"url": f"https://pr-{pull['number']}.{product_url}",
"status": label["name"].split(":")[1],
}
)
break
return HttpResponse("<br>".join(str(pull) for pull in pulls))