Last active
November 5, 2015 17:27
-
-
Save mblackstock/8949663 to your computer and use it in GitHub Desktop.
exporting git hub issues to CSV that is almost ready to import into JIRA. Based mostly on https://gist.github.com/unbracketed/3380407
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Exports Issues from a specified repository to a CSV file | |
Uses basic authentication (Github username + password) to retrieve Issues | |
from a repository that username has access to. Supports Github API v3. | |
""" | |
import csv | |
import requests | |
GITHUB_USER = '' | |
GITHUB_PASSWORD = '' | |
REPO = '' # format is username/repo | |
ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/%s/issues?state=open' % REPO #only open issues | |
AUTH = (GITHUB_USER, GITHUB_PASSWORD) | |
def write_issues(response): | |
"output a list of issues to csv" | |
if not r.status_code == 200: | |
raise Exception(r.status_code) | |
for issue in r.json(): | |
labels = issue['labels'] | |
for label in labels: | |
#only issues with 'wotkit' and 'processor' label | |
if label['name'] == "wotkit" or label['name']=="processor": | |
assignee = issue['assignee'] | |
if assignee is not None: | |
assignee = assignee['login'].encode('utf-8') | |
csvout.writerow([issue['number'], issue['title'].encode('utf-8'), | |
issue['body'].encode('utf-8'), | |
assignee, | |
issue['user']['login'].encode('utf-8'), | |
issue['created_at'],issue['updated_at']]) | |
r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH) | |
csvfile = '%s-issues.csv' % (REPO.replace('/', '-')) | |
csvout = csv.writer(open(csvfile, 'wb')) | |
csvout.writerow(('id','Summary', 'Description', 'Assignee', 'Reporter','Date Created','Date Updated')) | |
write_issues(r) | |
#more pages? examine the 'Link' header returned | |
if 'Link' in r.headers: | |
pages = dict([(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in | |
[link.split(';') for link in | |
r.headers['Link'].split(',')]]) | |
while 'last' in pages and 'next' in pages: | |
pages = dict([(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in | |
[link.split(';') for link in | |
r.headers['Link'].split(',')]]) | |
r = requests.get(pages['next'], auth=AUTH) | |
write_issues(r) | |
if pages['next'] == pages['last']: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am getting below "no json object could be decoded" error when I tried this code.. Any idea on this?
regress@vm-nomadic-ubuntu:~/git_issue/3380407$ python export_github_issues_csv.py
Traceback (most recent call last):
File "export_github_issues_csv.py", line 40, in
write_issues(r)
File "export_github_issues_csv.py", line 21, in write_issues
for issue in r.json():
File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 763, in json
return json.loads(self.text, **kwargs)
File "/usr/lib/python2.7/dist-packages/simplejson/init.py", line 413, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 420, in raw_decode
raise JSONDecodeError("No JSON object could be decoded", s, idx)
simplejson.decoder.JSONDecodeError: No JSON object could be decoded: line 6 column 1 (char 5)