From c6aaba574fedb9884b1390d183ec734c6254bc6d Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 26 2016 12:59:49 +0000 Subject: Add a widget to list tickets on a fedorahosted.org trac instance --- diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py index a365c3d..323aa70 100755 --- a/hubs/widgets/__init__.py +++ b/hubs/widgets/__init__.py @@ -15,6 +15,7 @@ from hubs.widgets import github_pr from hubs.widgets import pagureissues from hubs.widgets import githubissues from hubs.widgets import bugzilla +from hubs.widgets import fhosted from hubs.widgets.workflow import pendingacls from hubs.widgets.workflow import updates2stable @@ -39,6 +40,7 @@ registry = { 'pagureissues': pagureissues, 'githubissues': githubissues, 'bugzilla': bugzilla, + 'fedorahosted': fhosted, 'workflow.pendingacls': pendingacls, 'workflow.updates2stable': updates2stable, diff --git a/hubs/widgets/fhosted.py b/hubs/widgets/fhosted.py new file mode 100644 index 0000000..4f99f71 --- /dev/null +++ b/hubs/widgets/fhosted.py @@ -0,0 +1,56 @@ +from hubs.widgets.chrome import panel +from hubs.hinting import hint, prefixed as _ +from hubs.widgets.base import argument +from hubs.widgets import templating +import hubs.validators as validators +import requests + +chrome = panel("Fedorahosted: Open Tickets") +template = templating.environment.get_template('templates/fedorahosted.html') +position = 'right' + +from xmlrpclib import ServerProxy + + +@argument(name="project", + default=None, + validator=validators.github_organization, + help="Name of the trac instance on fedorahosted.org") +@argument(name="n_tickets", + default=4, + validator=validators.integer, + help="The number of tickets to display.") +def data(session, widget, project, n_tickets=4): + n_tickets = int(n_tickets) + url = 'https://fedorahosted.org/%s/rpc' % project + filters = 'status=accepted&status=assigned&status=new&status=reopened'\ + '&col=id&col=summary&col=status&col=owner&col=type&col=priority'\ + '&col=milestone&col=changetime&order=changetime' + server = ServerProxy(url) + tickets = server.ticket.query(filters) + output = [] + total_tickets = len(tickets) + for idx, ticket in enumerate(tickets): + ticket = server.ticket.get(ticket) + data = ticket[3] + data['id'] = ticket[0] + data['short_summary'] = data['summary'][:45] + output.append(data) + if idx + 1 >= n_tickets: + break + + return dict( + project=project, + tickets=output, + total_tickets=total_tickets, + ) + + +@hint(topics=[_('trac.ticket.update'), _('trac.ticket.new')]) +def should_invalidate(message, session, widget): + project = widget.config.get('project', '') + url = 'https://fedorahosted.org/%s/' % project + if '.trac.ticket' in message['topic']: + if message['msg']['instance']['base_url'] == url: + return True + return False diff --git a/hubs/widgets/templates/fedorahosted.html b/hubs/widgets/templates/fedorahosted.html new file mode 100644 index 0000000..4908362 --- /dev/null +++ b/hubs/widgets/templates/fedorahosted.html @@ -0,0 +1,41 @@ + + All Issues + +
+ +