From 7f1424e6fa96098dd063fc53eee2c85331cda047 Mon Sep 17 00:00:00 2001 From: Sayak Sarkar Date: Jul 26 2017 13:53:48 +0000 Subject: [PATCH 1/2] Dropped FedoraHosted widget. Fixes #354. --- diff --git a/hubs/default_config.py b/hubs/default_config.py index ab47804..3924a1f 100644 --- a/hubs/default_config.py +++ b/hubs/default_config.py @@ -60,7 +60,6 @@ WIDGETS = [ 'hubs.widgets.linechart:Linechart', 'hubs.widgets.fedmsgstats:FedmsgStats', 'hubs.widgets.feed:Feed', - 'hubs.widgets.fhosted:FedoraHosted', 'hubs.widgets.github_pr:GitHubPRs', 'hubs.widgets.githubissues:GitHubIssues', 'hubs.widgets.halp:Halp', diff --git a/hubs/widgets/fhosted/__init__.py b/hubs/widgets/fhosted/__init__.py deleted file mode 100644 index b17eb7a..0000000 --- a/hubs/widgets/fhosted/__init__.py +++ /dev/null @@ -1,89 +0,0 @@ -from __future__ import unicode_literals - -from six.moves.xmlrpc_client import ServerProxy - -from hubs.widgets import validators -from hubs.widgets.base import Widget -from hubs.widgets.view import RootWidgetView -from hubs.widgets.caching import CachedFunction - - -class FedoraHosted(Widget): - - name = "fhosted" - label = "Fedorahosted: Open Tickets" - position = "right" - parameters = [ - dict( - name="project", - label="Project", - default=None, - validator=validators.FedorahostedProject, - help="Name of the trac instance on fedorahosted.org.", - ), dict( - name="n_tickets", - label="Number of tickets", - default=4, - validator=validators.Integer, - help="The number of tickets to display.", - )] - - -class BaseView(RootWidgetView): - - def get_context(self, instance, *args, **kwargs): - get_tickets = GetTickets(instance) - context = dict( - title=self.widget.label, - project=instance.config["project"], - ) - context.update(get_tickets()) - return context - - -class GetTickets(CachedFunction): - ''' Data for Fedorahosted widget. - Queries Fedorahosted via xmlrpc for tickets. ''' - - def execute(self): - n_tickets = self.instance.config["n_tickets"] - url = 'https://fedorahosted.org/%s/rpc' \ - % self.instance.config["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' - - # get the tickets based on the filters - # returns a list of ticket ids - try: - server = ServerProxy(url) - tickets = server.ticket.query(filters) - except: - return dict( - error='Invalid or wrongly configured project' - ) - - output = [] - total_tickets = len(tickets) - for ticket in tickets[:n_tickets]: - # get the details of the ticket - ticket = server.ticket.get(ticket) - data = ticket[3] - data['id'] = ticket[0] - data['short_summary'] = data['summary'][:45] - output.append(data) - - return dict( - tickets=output, - total_tickets=total_tickets, - ) - - def should_invalidate(self, message): - ''' Checks if the Fedorahosted widget needs an update. - Called by backend daemon listening to fedmsg ''' - if '.trac.ticket' in message['topic']: - project = self.instance.config.get("project", "") - url = 'https://fedorahosted.org/%s/' % project - if message['msg']['instance']['base_url'] == url: - return True - return False diff --git a/hubs/widgets/fhosted/templates/root.html b/hubs/widgets/fhosted/templates/root.html deleted file mode 100644 index 5dcc574..0000000 --- a/hubs/widgets/fhosted/templates/root.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends "templates/panel.html" %} - -{% block content %} -{% if error %} -

{{ error }}

-{% else %} - - All Issues - -
- - -{% endif %} -{% endblock %} From 4d85c8ab7660d504bc4f08dd17fcdeff2280b8e6 Mon Sep 17 00:00:00 2001 From: Sayak Sarkar Date: Jul 26 2017 14:22:14 +0000 Subject: [PATCH 2/2] Removed the FedoraHostedProject validator along with its unit tests and VCR files. --- diff --git a/hubs/tests/test_widget_validators.py b/hubs/tests/test_widget_validators.py index 2cadf7f..ba0c2b8 100644 --- a/hubs/tests/test_widget_validators.py +++ b/hubs/tests/test_widget_validators.py @@ -57,11 +57,3 @@ class ValidatorsTest(APPTest): validators.PagureRepo.from_string("fedora-hubs"), "fedora-hubs") self.assertRaises(ValueError, validators.PagureRepo.from_string, "something-that-does-not-exist") - - def test_fedorahosted_project(self): - self.assertEqual( - validators.FedorahostedProject.from_string("about-fedora"), - "about-fedora") - self.assertRaises( - ValueError, validators.FedorahostedProject.from_string, - "something-that-does-not-exist") diff --git a/hubs/tests/vcr-request-data/hubs.tests.test_widget_validators.ValidatorsTest.test_fedorahosted_project b/hubs/tests/vcr-request-data/hubs.tests.test_widget_validators.ValidatorsTest.test_fedorahosted_project deleted file mode 100644 index 3d8315c..0000000 --- a/hubs/tests/vcr-request-data/hubs.tests.test_widget_validators.ValidatorsTest.test_fedorahosted_project +++ /dev/null @@ -1,186 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.13.0] - method: GET - uri: https://fedorahosted.org/about-fedora/ - response: - body: {string: "\n\n \n \n\n \n\n\n \n \n about-fedora\n \n\ - \ \n \n \n \n \n \n \n \n \n \n \n \n\ - \ \n \n \n
\n
\n \"Fedora\n
\n
\n
\n \n \n \n
\n
\n \n
\n \n
\n \n
\n

Context Navigation

\n \n
\n
\n
\n
\n \n \n\ - \
\n Last modified\ - \ 8 years ago\n \ - \ Last modified on 02/09/09 03:57:48\n\ - \
\n

What is this site?

\n

\nThis is the source project for About Fedora.\ - \ It includes a git repo and a database for tracking how we develop\ - \ the source toolchain. \n

\n

\nIt's all part of the \u200B\ - Fedora Project. This site, in particular, is run by the \u200BFedora Documentation team.\n

\n

\nIf you want\ - \ to look at what we've created, use the \"Browse Source\" link above and\ - \ to the right.\n

\n

About\ - \ Fedora has something missing or wrong.

\n

\nIf you need to tell us\ - \ that something is wrong in About Fedora, visit \u200BBugzilla.\ - \ File a bug against the product \"Fedora Documentation,\" component \"about-fedora\"\ - .\n

\n

I want to help with the content.

\n\ -

\nIf you want to help update the content of About Fedora, first \u200Bintroduce yourself to the Docs Project.\ - \ When you've done that, \u200Bjoin our project group. Then visit\ - \ \u200Bthis page on the Fedora Project wiki\ - \ to find out how to get started using git. These instructions should\ - \ work for most people with access to this repository:\n

\n
cd ~/projects/\ngit clone ssh://<username>@git.fedorahosted.org/git/docs/about-fedora.git\n\
-        git clone git://git.fedorahosted.org/git/fedora-doc-utils docs-common\n

\n\ - If you don't have access to this repo, use git:// instead of ssh://\ - \ above.\n

\n

I want\ - \ to translate the content to my language.

\n

\nCheck the \u200Bstatistics page to get details about\ - \ your language and join the \u200BFedora Translation team if your language\ - \ is not available.\n

\n

I'm confused.\ - \ What is this site for?

\n

\nIf you have questions, come visit the\ - \ Docs Project on IRC. IRC is a way to communicate in real time with other\ - \ Fedora Project members. You can find more information \u200Bhere.\n

\n
\n \n \n
\n\ - \ \n\n
\n
\n

Download in other\ - \ formats:

\n \n
\n
\n

\n \"Trac\n

Powered by Trac 0.12.5\n By Edgewall Software.Libravatar support by Tracvatar 1.9

\n

Visit the Trac open source\ - \ project at
http://trac.edgewall.org/

\n\ - \
\n \n \n\ - \ \n \n \n"} - headers: - cache-control: [must-revalidate] - connection: [Keep-Alive] - content-length: ['9437'] - content-type: [text/html;charset=utf-8] - date: ['Tue, 14 Feb 2017 10:57:38 GMT'] - expires: ['Fri, 01 Jan 1999 00:00:00 GMT'] - keep-alive: ['timeout=5, max=500'] - server: [Apache/2.2.15 (Red Hat)] - set-cookie: [trac_form_token=8344c426dbc2cc320d5e431d; Path=/about-fedora, 'trac_session=808a3fc5547b36ddaca5f057; - expires=Mon, 15-May-2017 10:57:39 GMT; Path=/about-fedora'] - strict-transport-security: [max-age=15768000; includeSubDomains; preload] - status: {code: 200, message: Ok} -- request: - body: null - headers: - Accept: ['*/*'] - Accept-Encoding: ['gzip, deflate'] - Connection: [keep-alive] - User-Agent: [python-requests/2.13.0] - method: GET - uri: https://fedorahosted.org/something-that-does-not-exist/ - response: - body: {string: !!python/unicode ' - - - - 302 Found - - - -

Found

- -

The document has moved here.

- -
- -
Apache/2.2.15 (Red Hat) Server at fedorahosted.org Port 443
- - - - '} - headers: - connection: [Keep-Alive] - content-length: ['300'] - content-type: [text/html; charset=iso-8859-1] - date: ['Tue, 14 Feb 2017 10:57:40 GMT'] - keep-alive: ['timeout=5, max=500'] - location: ['https://fedorahosted.org/web/410'] - server: [Apache/2.2.15 (Red Hat)] - strict-transport-security: [max-age=15768000; includeSubDomains; preload] - status: {code: 302, message: Found} -version: 1 diff --git a/hubs/widgets/validators.py b/hubs/widgets/validators.py index 98fef57..bf05a53 100644 --- a/hubs/widgets/validators.py +++ b/hubs/widgets/validators.py @@ -138,18 +138,6 @@ class PagureRepo(Validator): raise ValueError('Invalid pagure repo') -class FedorahostedProject(Validator): - """Fails if the FedoraHosted project name does not exist.""" - - @classmethod - def from_string(cls, value): - response = requests.get("https://fedorahosted.org/%s/" % value, - timeout=5, allow_redirects=False) - if response.status_code == 200: - return value - raise ValueError('Invalid fedorahosted project') - - class CommaSeparatedList(Validator): """Fails if the value isn't a comma-separated list.