Created
December 20, 2016 22:35
-
-
Save MattyAyOh/9a9e36c8a5a8b0d9400d2ba03ece340d to your computer and use it in GitHub Desktop.
This file contains 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
import csv | |
import requests | |
GITHUB_USER = '' | |
GITHUB_PASSWORD = '' | |
REPO = 'TechSmith/Snagit' # format is username/repo | |
ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/techsmith/snagit/issues?state=closed&labels=Bug' | |
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(): | |
# print issue | |
labelString = '' | |
labels = issue['labels'] | |
for label in labels: | |
labelString += (label['name'] + ";") | |
if "Bug" in labelString: | |
milestone = issue['milestone']['title'] | |
csvout.writerow([issue['number'], issue['title'].encode('utf-8'), labelString, milestone]) | |
r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH) | |
csvfile = '%s-issues.csv' % (REPO.replace('/', '-')) | |
csvout = csv.writer(open(csvfile, 'wb')) | |
csvout.writerow(('id', 'Title', 'Body')) | |
write_issues(r) | |
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(',')]]) | |
print "***" | |
print pages | |
while 'last' in pages and 'next' in pages: | |
print pages['next'] | |
r = requests.get(pages['next'], auth=AUTH) | |
write_issues(r) | |
if pages['next'] == pages['last']: | |
break | |
pages = dict( | |
[(rel[6:-1], url[url.index('<')+1:-1]) for url, rel in | |
[link.split(';') for link in | |
r.headers['link'].split(',')]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment