#82 Adds a bugzilla widget
Merged 8 years ago by ralph. Opened 8 years ago by dhrish20.
dhrish20/fedora-hubs issue39  into  develop

Adds a bugzilla widget
Dhriti Shikhar • 8 years ago  
Adds a bugzilla widget
Dhriti Shikhar • 8 years ago  
file modified
+6
@@ -73,4 +73,10 @@ 

              'display_number': 15,

          }))

      hub.widgets.append(widget)

+     widget = hubs.models.Widget(

+         plugin='bugzilla', index=8,

+         _config=json.dumps({

+             'username': username,

+         }))

+     hub.widgets.append(widget)

      return hub

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

  from hubs.widgets.workflow import updates2stable
@@ -37,6 +38,7 @@ 

      'github_pr': github_pr,

      'pagureissues': pagureissues,

      'githubissues': githubissues,

+     'bugzilla': bugzilla,

  

      'workflow.pendingacls': pendingacls,

      'workflow.updates2stable': updates2stable,

@@ -0,0 +1,90 @@ 

+ import requests

+ import jinja2

+ import pkgwat.api

+ 

+ import hubs.validators as validators

+ from hubs.widgets.base import argument

+ from hubs.widgets.chrome import panel

+ from hubs.hinting import hint, prefixed as _

+ 

+ chrome = panel("Bugzilla: Issues")

+ 

+ template = jinja2.Template("""

+ <ul class="media-list">

+   {% for item in issues %}

+     <li class="media">

+       <div class="media-left">

+         <a href="https://bugzilla.redhat.com/show_bug.cgi?id=

+         {{ item['id'] }}" target="_blank">

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

+         </a>

+       </div>

+       <div class="media-body">

+         <h4 class="media-heading">

+           <a href="https://admin.fedoraproject.org/pkgdb/

+           package/rpms/{{ item['pkg_name'] }}" target=

+           "_blank">{{ item['pkg_name'] }}</a>:

+           {{ item['title'] }}

+         </h4>

+       </div>

+     </li>

+   {% endfor %}

+ </ul>

+ """)

+ 

+ 

+ @argument(name="username",

+           default=None,

+           validator=validators.username,

+           help="A FAS username.")

+ def data(session, widget, username):

+     pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"

+     url = "/".join([pkgdb_url, username])

+     response = requests.get(url)

+     data = response.json()

+ 

+     issues = []

+ 

+     for package in data["point of contact"]:

+         if len(issues) == 3:

+             break

+         else:

+             pkg_details=pkgwat.api.bugs(package['name'])

+             for row in pkg_details['rows']:

+                 if len(issues) == 3:

+                     break

+                 else:

+                     issues.append(

+                         dict(

+                           id=row['id'],

+                           title=row['description'],

+                           pkg_name=package['name'],

+                           )

+                         )

+ 

+     for package in data["co-maintained"]:

+         if len(issues) == 3:

+             break

+         else:

+             pkg_details=pkgwat.api.bugs(package['name'])

+             for row in pkg_details['rows']:

+                 if len(issues) == 3:

+                     break

+                 else:

+                     issues.append(

+                         dict(

+                             id=row['id'],

+                             title=row['description'],

+                             pkg_name=package['name'],

+                             )

+                         )

+ 

+     return dict(

+       username=username,

+       issues=issues,

+     )

+ 

+ 

+ @hint()

+ def should_invalidate(message, session, widget):

+     raise NotImplementedError

no initial comment

You could simplify this by simply using for issue in all_issues[:3]
but then if you don't want all the issues, maybe you could store only the first 3 directly?

Same here, you could simply use for row in pkg_details['rows']

Which later allows you do to: issue_title=row['description'],

Pull-Request has been rebased

8 years ago

I have made the changes. This is the screenshot: https://cdn.pbrd.co/images/247rnUWk.png

Do we need to keep in memory all the issues if we only display the first three?

Pull-Request has been updated

8 years ago

@pingou i have made changes to store only 3 issues in all_issues

nitpicking here but it's recommended to use [] as it's faster than list()

Pull-Request has been updated

8 years ago

Pull-Request has been updated

8 years ago

Can you arrange the imports separating the in-built modules, third-party modules and project imports

Pull-Request has been updated

8 years ago

if you limit the number of issues below then:

  • all_issues is probably invalid as variable name
  • [:3] here is probably not needed

Something that confuses me: here we get the last 3 bugs for all the packages, but we still only
display 3 in the templates, so we may still end up with 20 packages * 3 bugs == 60 bugs in
while we only show 3.

Pull-Request has been updated

8 years ago

Pull-Request has been updated

8 years ago

Maybe you could check before the length of allissues
(whose name is no longer correct) to avoid querying for more
bugs while you already have enough?

This will break the loop for row in pkg_details['rows']: but not the outer one (for package in data["point of contact"]:)

Pull-Request has been updated

8 years ago

But if we have more than 4 rows here, we will never trigger the check above :)

Pull-Request has been updated

8 years ago

Pull-Request has been updated

8 years ago

@threebean can you please review this PR?

Sorry, I hadn't commented because I thought @pingou and @sayanchowdhury were on it.

Looks great. Thanks so much @dhrish20!

Pull-Request has been merged by ralph

8 years ago