#56 Adds a pagure pull requests widget
Merged 8 years ago by ralph. Opened 8 years ago by dhrish20.
dhrish20/fedora-hubs issue38  into  develop

Adds a pagure pull requests widget
Dhriti Shikhar • 8 years ago  
file modified
+7
@@ -53,4 +53,11 @@ 

              '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

file modified
+3
@@ -22,3 +22,6 @@ 

      return value in [

          'irc', 'email', 'android', 'desktop', 'hubs',

      ]

+ 

+ def repo(session, value):

+     return value

@@ -11,6 +11,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.workflow import pendingacls

  from hubs.widgets.workflow import updates2stable
@@ -31,6 +32,7 @@ 

      'subscriptions': subscriptions,

      'cobwebs': cobwebs,

      'meetings': meetings,

+     'pagure_pr': pagure_pr,    

  

      'workflow.pendingacls': pendingacls,

      'workflow.updates2stable': updates2stable,

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

+   <br />

+     <div class="container">

+       {% for i in range(0,total_req) %}

+         <div>

+           <table class="table-responsive table-condensed">

+             <tr>

+               <td valign="top" class="panel-heading">

+                 <b>#{{ all_pr[i]['pr_id'] }}</b>

+               </td>

+               <td width="260px">

+                 <b>{{ all_pr[i]['pr_title'] }} ...</b>

+               </td>

+             </tr>

+            </table>

+          <table class="table-responsive table-condensed">

+             <tr>

+               <td width="280px" >

+                 <font size="2">

+                   <i>Opened by <a href="https://pagure.io/user/{{ all_pr[i]['pr_openedby'] }}" target="_blank">{{ all_pr[i]['pr_openedby'] }}</a>

+                   {% if all_pr[i]['pr_assignee'] %}

+                     <br>Assigned to <a href="https://pagure.io/user/{{ all_pr[i]['pr_assignee'] }}" target="_blank">{{ all_pr[i]['pr_assignee'] }}</a></i>

+                   {% endif %}

+                 </font>

+               </td>

+               <td>

+                 <a href="https://pagure.io/{{ repo }}/pull-request/{{ all_pr[i]['pr_id'] }}" target="_blank">

+                   <button type="button" class="btn btn-default" aria-label="Left Align">

+                     <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>

+                   </button>

+                 </a>

+               </td>

+             </tr>

+           </table>

+         </div>

+       {%endfor%}

+     <br />

+     </div class="row">

+       <center><a href="https://pagure.io/{{ repo }}/pull-requests" target="_blank">All Pull-Requests</a><center>

+     </div>

+   </div>

+ """)

+ 

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

no initial comment

A couple things seem off here.

  • The 'assignee' is the person assigned to fix the bug. They did not "open" the bug, as the text says here.
  • Odd that their name is a hyperlink to the bug. Should their name be a hyperlink to their hubs page instead?

Should be pagure.io/{repo}/ here, no?

Could this be simplified like:

all_pr.append(dict(
   id=data['requests'][i]['id'],
   title=data['requests'][i]['title'],
   assignee=data['requests'][i]['user']['name'],
))

Screenshot looks very nice! :)

Looks like a great start!

According to threebean: The "opened by" text is actually who the issue was assigned to, so you should change that.

Once you've got that changed, I'll check back in with you.

+1

@ralph I have updated the PR.

I have made changes:
[1] corrected "opened by" and "assigned to"
[2] limited the characters of pr_title to 45 characters

This is the final screenshot now:
https://cdn.pbrd.co/images/2cnlyEQS.png

Looks good! Let's merge it. :)

Thanks @dhrish20!