From 1e1b6dcf38331e264f70ad84690743744b0c3c33 Mon Sep 17 00:00:00 2001
From: Dhriti Shikhar <dhrish20@gmail.com>
Date: Mar 06 2016 15:17:59 +0000
Subject: [PATCH 1/2] Adds a bugzilla widget


---

diff --git a/hubs/defaults.py b/hubs/defaults.py
index 3629062..c37b6cb 100644
--- a/hubs/defaults.py
+++ b/hubs/defaults.py
@@ -73,4 +73,10 @@ def add_user_widgets(session, hub, username, fullname):
             '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
diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py
index 03084ac..cc7007c 100644
--- a/hubs/widgets/__init__.py
+++ b/hubs/widgets/__init__.py
@@ -14,6 +14,7 @@ from hubs.widgets import pagure_pr
 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 @@ registry = {
     'github_pr': github_pr,
     'pagureissues': pagureissues,
     'githubissues': githubissues,
+    'bugzilla': bugzilla,
 
     'workflow.pendingacls': pendingacls,
     'workflow.updates2stable': updates2stable,
diff --git a/hubs/widgets/bugzilla.py b/hubs/widgets/bugzilla.py
new file mode 100644
index 0000000..bce887d
--- /dev/null
+++ b/hubs/widgets/bugzilla.py
@@ -0,0 +1,76 @@
+import operator
+import requests
+from hubs.hinting import hint, prefixed as _
+from hubs.widgets.base import argument
+import jinja2
+import hubs.validators as validators
+from hubs.widgets.chrome import panel
+import pkgwat.api
+
+chrome = panel("Bugzilla: Issues")
+
+template = jinja2.Template("""
+<ul class="media-list">
+  {% for issue in all_issues[:3] %}
+    <li class="media">
+      <div class="media-left">
+        <a href="https://bugzilla.redhat.com/show_bug.cgi?id={{ issue['id'] }}" target="_blank">
+	  <span class="label label-default">#{{ issue['id'] }}</span>
+	</a>
+      </div>
+      <div class="media-body">
+        <h4 class="media-heading">
+          <a href="https://admin.fedoraproject.org/pkgdb/package/rpms/{{ issue['pkg_name'] }}" target="_blank">{{ issue['pkg_name'] }}</a> -
+          {{ issue['title'] }}
+        </h4>
+      </div>
+    </li>
+  {% endfor %}
+</ul>
+""")
+
+@argument(name="username",
+          default=None,
+          validator=validators.username,
+          help="A FAS username.")
+def data(session, widget, username):
+    username=username
+    pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"
+    url = "/".join([pkgdb_url, username])
+    response = requests.get(url)
+    data = response.json()
+    total_poc = len(data["point of contact"])
+    total_co_main = len(data["co-maintained"])
+    
+    all_issues = list()
+    
+    for package in data["point of contact"]:
+      pkg_details=pkgwat.api.bugs(package['name'])
+      for row in pkg_details['rows']:
+        all_issues.append(
+          dict(
+            pkg_name=package['name'],
+            id=row['id'],
+            title=row['description'],
+          )
+        ) 
+      
+    for package in data["co-maintained"]:
+      pkg_details=pkgwat.api.bugs(package['name'])
+      for row in pkg_details['rows']:
+        all_issues.append(
+          dict(
+            pkg_name=package['name'],
+            id=row['id'],
+            title=row['description'],
+          )
+        )
+
+    return dict(
+      username=username,
+      all_issues=all_issues,
+    )
+
+@hint()
+def should_invalidate(message, session, widget):
+    raise NotImplementedError

From 7624b3f983a71f513643963f052debb49e771d83 Mon Sep 17 00:00:00 2001
From: Dhriti Shikhar <dhrish20@gmail.com>
Date: Mar 14 2016 19:41:32 +0000
Subject: [PATCH 2/2] Adds a bugzilla widget


1. Changes the variable name allissues to issues
2. Changes according to PEP8

---

diff --git a/hubs/widgets/bugzilla.py b/hubs/widgets/bugzilla.py
index bce887d..5482829 100644
--- a/hubs/widgets/bugzilla.py
+++ b/hubs/widgets/bugzilla.py
@@ -1,27 +1,30 @@
-import operator
 import requests
-from hubs.hinting import hint, prefixed as _
-from hubs.widgets.base import argument
 import jinja2
+import pkgwat.api
+
 import hubs.validators as validators
+from hubs.widgets.base import argument
 from hubs.widgets.chrome import panel
-import pkgwat.api
+from hubs.hinting import hint, prefixed as _
 
 chrome = panel("Bugzilla: Issues")
 
 template = jinja2.Template("""
 <ul class="media-list">
-  {% for issue in all_issues[:3] %}
+  {% for item in issues %}
     <li class="media">
       <div class="media-left">
-        <a href="https://bugzilla.redhat.com/show_bug.cgi?id={{ issue['id'] }}" target="_blank">
-	  <span class="label label-default">#{{ issue['id'] }}</span>
-	</a>
+        <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/{{ issue['pkg_name'] }}" target="_blank">{{ issue['pkg_name'] }}</a> -
-          {{ issue['title'] }}
+          <a href="https://admin.fedoraproject.org/pkgdb/
+          package/rpms/{{ item['pkg_name'] }}" target=
+          "_blank">{{ item['pkg_name'] }}</a>:
+          {{ item['title'] }}
         </h4>
       </div>
     </li>
@@ -29,48 +32,59 @@ template = jinja2.Template("""
 </ul>
 """)
 
+
 @argument(name="username",
           default=None,
           validator=validators.username,
           help="A FAS username.")
 def data(session, widget, username):
-    username=username
     pkgdb_url = "https://admin.fedoraproject.org/pkgdb/api/packager/package"
     url = "/".join([pkgdb_url, username])
     response = requests.get(url)
     data = response.json()
-    total_poc = len(data["point of contact"])
-    total_co_main = len(data["co-maintained"])
-    
-    all_issues = list()
-    
+
+    issues = []
+
     for package in data["point of contact"]:
-      pkg_details=pkgwat.api.bugs(package['name'])
-      for row in pkg_details['rows']:
-        all_issues.append(
-          dict(
-            pkg_name=package['name'],
-            id=row['id'],
-            title=row['description'],
-          )
-        ) 
-      
+        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"]:
-      pkg_details=pkgwat.api.bugs(package['name'])
-      for row in pkg_details['rows']:
-        all_issues.append(
-          dict(
-            pkg_name=package['name'],
-            id=row['id'],
-            title=row['description'],
-          )
-        )
+        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,
-      all_issues=all_issues,
+      issues=issues,
     )
 
+
 @hint()
 def should_invalidate(message, session, widget):
     raise NotImplementedError

