From 726e6d5db3e3d80a3a66239696bfaf5a4064c8ea Mon Sep 17 00:00:00 2001 From: Dhriti Shikhar Date: Dec 01 2015 15:31:34 +0000 Subject: Adds a github pull requests widget --- diff --git a/hubs/defaults.py b/hubs/defaults.py index 56a93c1..228aab1 100644 --- a/hubs/defaults.py +++ b/hubs/defaults.py @@ -59,5 +59,12 @@ def add_user_widgets(session, hub, username, fullname): 'repo': 'pagure', })) hub.widgets.append(widget) - + widget = hubs.models.Widget( + plugin='github_pr', index=7, + _config=json.dumps({ + 'display_number': 1, + 'org': 'fedora-infra', + 'repo': 'fas', + })) + hub.widgets.append(widget) return hub diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py index 416f7d6..624f139 100644 --- a/hubs/widgets/__init__.py +++ b/hubs/widgets/__init__.py @@ -12,6 +12,7 @@ from hubs.widgets import subscriptions from hubs.widgets import cobwebs from hubs.widgets import meetings from hubs.widgets import pagure_pr +from hubs.widgets import github_pr from hubs.widgets.workflow import pendingacls from hubs.widgets.workflow import updates2stable @@ -33,6 +34,7 @@ registry = { 'cobwebs': cobwebs, 'meetings': meetings, 'pagure_pr': pagure_pr, + 'github_pr': github_pr, 'workflow.pendingacls': pendingacls, 'workflow.updates2stable': updates2stable, diff --git a/hubs/widgets/github_pr.py b/hubs/widgets/github_pr.py new file mode 100644 index 0000000..3ec8ab1 --- /dev/null +++ b/hubs/widgets/github_pr.py @@ -0,0 +1,85 @@ +from hubs.widgets.chrome import panel +from hubs.hinting import hint +from hubs.widgets.base import argument +import hubs.validators as validators +import jinja2 +import requests + +chrome = panel("Github: Open Pull Requests") + +template = jinja2.Template(""" +
+ {% for i in range(display_number) %} +
+ + + + + +
+ #{{ all_pr[i]['num'] }} + + {{ all_pr[i]['title'] }} +
+ + + + + +
+ + Opened by {{ all_pr[i]['openedby'] }} + {% if all_pr[i]['assignee']|string() == "None" %} +
Unclaimed + {% else %} +
Assigned by {{ all_pr[i]['assignee'] }} + {% endif %} +
+
+ + + +
+
+ {% endfor %} +
+
All Pull Requests
+
+""") + +@argument(name="repo", + default=None, + validator=validators.repo, + help="Repo") +def data(session, widget, display_number, org, repo): + url = '/'.join(['https://api.github.com/repos',org,repo,"pulls"]) + pr_response = requests.get(url) + data = pr_response.json() + all_pr = list() + for i in range(0,1): + pr_details=dict() + pr_num=data[i]['number'] + pr_title=data[i]['title'] + pr_openedby=data[i]['user']['login'] + if(data[i]['assignee']!=None): + pr_assignee=data[i]['assignee']['login'] + else: + pr_assignee=data[i]['assignee'] + pr_details['num']=pr_num + pr_details['title']=pr_title + pr_details['openedby']=pr_openedby + pr_details['assignee']=pr_assignee + all_pr.append(pr_details) + all_pr.reverse() + return dict( + org=org, + repo=repo, + all_pr=all_pr, + display_number=display_number, + ) + +@hint() +def should_invalidate(message, session, widget): + raise NotImplementedError