#229 Add the trac widget for ticket coming from fedorahosted
Merged 7 years ago by pingou. Opened 7 years ago by pingou.
pingou/fedora-hubs trac_widget  into  develop

file modified
+5 -1
@@ -27,7 +27,7 @@ 

  

  def github_organization(session, value):

      # TODO -- implement this.

-     return True

+     return value

Confused by this line? But im assuming this wan't needed to fix this pr but was something needed to be done

Indeed, we want the validators to return the value, not a True/False

  

  

  def fmn_context(session, value):
@@ -39,3 +39,7 @@ 

  

  def pagure_repo(session, value):

      return value

+ 

+ def fedorahosted_project(session, value):

+     # TODO -- implement this.

+     return value

@@ -15,6 +15,7 @@ 

  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 @@ 

      'pagureissues': pagureissues,

      'githubissues': githubissues,

      'bugzilla': bugzilla,

+     'fedorahosted': fhosted,

  

      'workflow.pendingacls': pendingacls,

      'workflow.updates2stable': updates2stable,

@@ -0,0 +1,62 @@ 

+ 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.fedorahosted_project,

+           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'

+     try:

+         server = ServerProxy(url)

+         tickets = server.ticket.query(filters)

+     except:

+         return dict(

+             error='Invalid or wrongly configured project'

+         )

+ 

+     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

@@ -69,6 +69,7 @@ 

            validator=validators.integer,

            help="The number of meetings to display.")

  def data(session, widget, calendar, n_meetings=4):

+     n_meetings = int(n_meetings)

      base = 'https://apps.fedoraproject.org/calendar/api/meetings/?calendar=%s'

      url = base % calendar

      response = requests.get(url).json()

@@ -0,0 +1,44 @@ 

+ {% if error %}

+ <p>{{ error }}</p>

+ {% else %}

+ <a class="btn btn-success" target="_blank"

+     href="https://fedorahosted.org/{{ project }}/report/1">

+   All Issues

+ </a>

+ <hr/>

+ 

+ <ul class="media-list">

+   {% for issue in tickets %}

+     <li class="media">

+       <div class="media-left">

+         <a  href="https://fedorahosted.org/{{ project }}/ticket/{{ issue['id'] }}"

+             target="_blank">

+         <span class="label label-default">#{{ issue['id'] }}</span>

+         </a>

+       </div>

+       <div class="media-body">

+         <h4 class="media-heading">

+           <span title="{{ issue['summary'] }}">

+             {{ issue['short_summary'] }} {% if

+               issue['summary'] | length > 45 %} ... {% endif %}

+           </span>

+         </h4>

+         Opened by:

+             {{ issue['reporter'] }}

+         --

+         {% if issue['owner'] %}

+           Assigned to:

+             {{issue['owner'] }}

+         {% else %}

+           <span class="text-muted">Unassigned</span>

+         {% endif %}

+       </div>

+     </li>

+   {% endfor %}

+   {% if total_tickets > tickets | length %}

+   <li>

+     And {{ total_tickets - tickets | length }} more ...

+   </li>

+   {% endif %}

+ </ul>

+ {% endif %}

@@ -25,7 +25,7 @@ 

            Assigned to:

            <a href="https://pagure.io/user/{{ pr['pr_assignee'] }}"

                target="_blank">

-             {{ pr['pr_assignee'] }}

+             {{ pr['pr_assignee']['name'] }}

            </a>

          {% else %}

            <span class="text-muted">Unassigned</span>

Fixes https://pagure.io/fedora-hubs/issue/174

Fixes as well a couple of small issue to the Pagure PR widget and the meetings one

When I enter gibberish into the project name it returns

Got an error retrieving this widget. Sorry :(

I'd like it to note that

project is either non-existent or connection timed out

Because now I'm unable to edit the project name

Adding the widget works correctly and looks good. However, updating the number of tickets to display causes the widget to break. traceback

1 new commit added

  • Show an error message upon error :)
7 years ago

After manually updating the db for this widget project to "fedocal". It loads fine. When I try to update the number of issues it reverts the project to true again.

1 new commit added

  • Fix the validator used in the fedorahosted widget
7 years ago

Confused by this line? But im assuming this wan't needed to fix this pr but was something needed to be done

Indeed, we want the validators to return the value, not a True/False

This works for me :)

even with negative number in posts 1 issue is shown which is ideal :)

:thumbsup: lgtm

Works for me now :thumbsup:

Thanks for the reviews :)

Pull-Request has been merged by pingou

7 years ago