From 3255f78537164f502e5d6998485c4663e0953880 Mon Sep 17 00:00:00 2001
From: Dhriti Shikhar <dhrish20@gmail.com>
Date: Dec 01 2015 14:42:31 +0000
Subject: Adds a github issues widget


---

diff --git a/hubs/defaults.py b/hubs/defaults.py
index 56a93c1..1348953 100644
--- a/hubs/defaults.py
+++ b/hubs/defaults.py
@@ -59,5 +59,12 @@ def add_user_widgets(session, hub, username, fullname):
             'repo': 'pagure',
         }))
     hub.widgets.append(widget)
-
+    widget = hubs.models.Widget(
+        plugin='githubissues', index=6,
+        _config=json.dumps({
+            'display_number': 3,
+            'org' : 'fedora-infra',
+            'repo': 'fas',
+        }))
+    hub.widgets.append(widget)
     return hub
diff --git a/hubs/widgets/__init__.py b/hubs/widgets/__init__.py
index 416f7d6..e679714 100644
--- a/hubs/widgets/__init__.py
+++ b/hubs/widgets/__init__.py
@@ -12,6 +12,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 import githubissues
 
 from hubs.widgets.workflow import pendingacls
 from hubs.widgets.workflow import updates2stable
@@ -33,6 +34,7 @@ registry = {
     'cobwebs': cobwebs,
     'meetings': meetings,
     'pagure_pr': pagure_pr,    
+    'githubissues': githubissues,
 
     'workflow.pendingacls': pendingacls,
     'workflow.updates2stable': updates2stable,
diff --git a/hubs/widgets/githubissues.py b/hubs/widgets/githubissues.py
new file mode 100644
index 0000000..3eef711
--- /dev/null
+++ b/hubs/widgets/githubissues.py
@@ -0,0 +1,85 @@
+from hubs.widgets.chrome import panel
+from hubs.hinting import hint
+from hubs.widgets.base import argument
+import hubs.validators as validators
+import jinja2
+import requests
+
+chrome = panel("Github: Newest Open Tickets")
+
+template = jinja2.Template("""
+  <br />
+  {% for i in range(display_number) %}
+    <div>
+      <table class="table-responsive table-condensed">
+        <tr>
+          <td valign="top" class="panel-heading">
+            <b>#{{ all_issues[i]['num'] }}</b>
+          </td>
+          <td width="300px">
+            <b>{{ all_issues[i]['title'] }}</b>
+          </td>
+        </tr>
+      </table>
+      <table class="table-responsive table-condensed">
+        <tr>
+          <td width="300px">
+            <font size="2">
+              <i>Opened by <a href="https://github.com/{{ all_issues[i]['openedby'] }}" target="_blank">{{ all_issues[i]['openedby'] }}</a></i>
+              {% if all_issues[i]['assignee']|string() == "None" %}
+                <br /><i>Unclaimed</i>
+              {% else %}
+                 <br /><i>Assigned by <a href="https://github.com/{{ all_issues[i]['assignee'] }}" target="_blank">{{ all_issues[i]['assignee'] }}</a></i>
+              {% endif %}
+            </font>
+          </td>
+          <td>
+             <a href="https://github.com/{{ org }}/{{ repo }}/issues/{{ all_issues[i]['num'] }}" 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 %}
+    <div class="row">
+      <a href="https://github.com/{{ org }}/{{ repo }}/issues" target="_blank"><center>All Issues</center></a>
+    </div>
+""")
+
+@argument(name="repo",
+	default=None,
+	validator=validators.repo,
+	help="Repo")
+def data(session, widget, display_number, org, repo):
+  url = '/'.join(['https://api.github.com/repos',org,repo,"issues"])
+  issue_response = requests.get(url)
+  data = issue_response.json()
+  all_issues = list()
+  for i in range(0,10):
+    issue_details=dict()
+    issue_num=data[i]['number']
+    issue_title=data[i]['title']
+    issue_openedby=data[i]['user']['login']
+    if(data[i]['assignee']!=None):
+      issue_assignee=data[i]['assignee']['login']
+    else:
+      issue_assignee=data[i]['assignee']
+    issue_details['num']=issue_num
+    issue_details['title']=issue_title
+    issue_details['openedby']=issue_openedby
+    issue_details['assignee']=issue_assignee
+    all_issues.append(issue_details)
+  all_issues.reverse()
+  return dict(
+    org=org,
+    repo=repo,
+    all_issues=all_issues,
+    display_number=display_number,
+  )
+
+@hint()
+def should_invalidate(message, session, widget):
+  raise NotImplementedError

