From aae7e26f50cb64cceafa1b5ac1a835ebbdf52ad1 Mon Sep 17 00:00:00 2001 From: Dhriti Shikhar Date: Nov 17 2015 05:36:17 +0000 Subject: Adds a pagure pull requests widget --- diff --git a/hubs/defaults.py b/hubs/defaults.py index ce29c74..56a93c1 100644 --- a/hubs/defaults.py +++ b/hubs/defaults.py @@ -53,4 +53,11 @@ def add_user_widgets(session, hub, username, fullname): 'username': username, })) hub.widgets.append(widget) + widget = hubs.models.Widget( + plugin='pagure_pr', index=5, + _config=json.dumps({ + 'repo': 'pagure', + })) + hub.widgets.append(widget) + return hub diff --git a/hubs/validators.py b/hubs/validators.py index 5bdf053..8248b29 100644 --- a/hubs/validators.py +++ b/hubs/validators.py @@ -22,3 +22,6 @@ def fmn_context(session, value): return value in [ 'irc', 'email', 'android', 'desktop', 'hubs', ] + +def repo(session, value): + return value diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py index d3ae5b5..9865be6 100644 --- a/hubs/widgets/__init__.py +++ b/hubs/widgets/__init__.py @@ -11,6 +11,7 @@ from hubs.widgets import feed from hubs.widgets import subscriptions from hubs.widgets import cobwebs from hubs.widgets import meetings +from hubs.widgets import pagure_pr from hubs.widgets.workflow import pendingacls from hubs.widgets.workflow import updates2stable @@ -31,6 +32,7 @@ registry = { 'subscriptions': subscriptions, 'cobwebs': cobwebs, 'meetings': meetings, + 'pagure_pr': pagure_pr, 'workflow.pendingacls': pendingacls, 'workflow.updates2stable': updates2stable, diff --git a/hubs/widgets/pagure_pr.py b/hubs/widgets/pagure_pr.py new file mode 100644 index 0000000..f00ffd2 --- /dev/null +++ b/hubs/widgets/pagure_pr.py @@ -0,0 +1,80 @@ +from hubs.hinting import hint +from hubs.widgets.chrome import panel +import jinja2 +import requests +from hubs.widgets.base import argument +import hubs.validators as validators +chrome = panel("Pagure: Newest Open Pull Requests") + +pagure_url = "https://pagure.io/api/0" + +template = jinja2.Template(""" +
+
+ {% for i in range(0,total_req) %} +
+ + + + + +
+ #{{ all_pr[i]['pr_id'] }} + + {{ all_pr[i]['pr_title'] }} ... +
+ + + + + +
+ + Opened by {{ all_pr[i]['pr_openedby'] }} + {% if all_pr[i]['pr_assignee'] %} +
Assigned to {{ all_pr[i]['pr_assignee'] }}
+ {% endif %} +
+
+ + + +
+
+ {%endfor%} +
+
+
All Pull-Requests
+ + +""") + +@argument(name="repo", + default=None, + validator=validators.repo, + help="Repo") +def data(session, widget, repo): + repo="pagure" + url = '/'.join([pagure_url, repo, "pull-requests"]) + response = requests.get(url) + data = response.json() + total_req = data['total_requests'] + all_pr = list() + for i in range(0,total_req): + all_pr.append(dict( + pr_id=data['requests'][i]['id'], + pr_title=data['requests'][i]['title'][:45], + pr_openedby=data['requests'][i]['user']['name'], + pr_assignee=data['requests'][i]['assignee'], + )) + all_pr.reverse() + return dict(all_pr=all_pr, + total_req=total_req, + repo=repo, +) + +@hint() +def should_invalidate(message, session, widget): + raise NotImplementedError