From 9de445398824efe96fcee5efa534f5dbe9357dda Mon Sep 17 00:00:00 2001 From: Vivek Anand Date: Oct 01 2016 17:11:51 +0000 Subject: Some code beautification in bugzilla widget --- diff --git a/hubs/widgets/bugzilla.py b/hubs/widgets/bugzilla.py index 856f975..a33e318 100644 --- a/hubs/widgets/bugzilla.py +++ b/hubs/widgets/bugzilla.py @@ -11,11 +11,15 @@ chrome = panel("Bugzilla: Issues") template = templating.environment.get_template('templates/bugzilla.html') position = 'right' + @argument(name="username", default=None, validator=validators.username, help="A FAS username.") def data(session, widget, username): + ''' Returns data for Bugzilla Widget. Queries pkgdb api for package + list of the user and bugzilla for correspoding issues ''' + pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package" url = "/".join([pkgdb_url, username]) response = requests.get(url) @@ -23,48 +27,51 @@ def data(session, widget, username): issues = [] + # get the packages of which the user is + # point of contact 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'], - ) - ) + pkg_details = pkgwat.api.bugs(package['name']) + for row in pkg_details['rows']: + if len(issues) == 3: + break + issues.append( + dict( + id=row['id'], + title=row['description'], + pkg_name=package['name'], + ) + ) + # get the packages of which the user is + # co maintainer 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'], - ) - ) + pkg_details = pkgwat.api.bugs(package['name']) + for row in pkg_details['rows']: + if len(issues) == 3: + break + issues.append( + dict( + id=row['id'], + title=row['description'], + pkg_name=package['name'], + ) + ) return dict( - username=username, - issues=issues, + username=username, + issues=issues, ) @hint(categories=['bugzilla']) def should_invalidate(message, session, widget): + ''' Validate if the bugzilla widget cache needs an update + This is called by a backend daemon listening to fedmsg ''' + # TODO -- wrap this pkgdb pull in another invalidatible cache. username = widget.config['username'] pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"