Added new field "assignee" & fix password pass as argument.

Resolves openbmc/openbmc-test-automation#324

Change-Id: I425c35bcd273ea0bd920b063efe023064e9fb0c8
Signed-off-by: Sivas SRR <sivas.srr@in.ibm.com>
diff --git a/tools/github_issues_to_csv b/tools/github_issues_to_csv
index b51347e..a8dd6b3 100644
--- a/tools/github_issues_to_csv
+++ b/tools/github_issues_to_csv
@@ -7,7 +7,7 @@
 """
 import argparse
 import csv
-from getpass import getpass
+import getpass
 import requests
 
 auth = None
@@ -24,17 +24,27 @@
     for issue in response.json():
         if 'pull_request' not in issue:
             labels = ', '.join([l['name'] for l in issue['labels']])
-            date = issue['created_at'].split('T')[0]
+            date = issue.get('created_at').split('T')[0]
+            # Below lines to overcome "TypeError: 'NoneType' object has
+            # no attribute '__getitem__'"
+
+            assignee_resp = issue.get('assignee', 'Not Assigned')
+            if assignee_resp:
+                assignee_resp = assignee_resp.get('login').encode('utf-8')
+            else:
+                assignee_resp = "Not Assigned"
+
             # Change the following line to write out additional fields
             csv_out.writerow([labels.encode('utf-8'),
-                             issue['title'].encode('utf-8'),
-                             issue['state'].encode('utf-8'),
+                             issue.get('title').encode('utf-8'),
+                             issue.get('state').encode('utf-8'),
                              date.encode('utf-8'),
-                             issue['html_url'].encode('utf-8'),
-                             issue['user']['login'].encode('utf-8')])
+                             issue.get('html_url').encode('utf-8'),
+                             issue.get('user').get('login').encode('utf-8'),
+                             assignee_resp])
 
 
-def get_github_issues(name):
+def get_issues_from_github_to_csv(name):
     r"""
     Requests issues from GitHub API and writes to CSV file.
     """
@@ -49,7 +59,8 @@
     csvfilename = '{}-issues.csv'.format(name.replace('/', '-'))
     with open(csvfilename, 'w') as csvfile:
         csv_out = csv.writer(csvfile)
-        csv_out.writerow(['Labels', 'Title', 'State', 'Date', 'URL', 'Author'])
+        csv_out.writerow(['Labels', 'Title', 'State', 'Date', 'URL', 'Author',
+                         'Assignee'])
         write_issues(response, csv_out)
 
         # Multiple requests are required if response is paged
@@ -74,9 +85,6 @@
 parser.add_argument('username', nargs='+', help="GitHub user name, "
                     "formatted as 'username'")
 
-parser.add_argument('password', nargs='+', help="GitHub username password, "
-                    "formatted as 'password'")
-
 parser.add_argument('repositories', nargs='+', help="Repository names, "
                     "formatted as 'basereponame/repo'")
 
@@ -90,10 +98,9 @@
 for argusername in args.username:
     username = argusername
 
-for argpassword in args.password:
-    password = argpassword
+password = getpass.getpass("Enter your GitHub Password:")
 
 auth = (username, password)
 
 for repository in args.repositories:
-    get_github_issues(repository)
+    get_issues_from_github_to_csv(repository)