Skip to content

Instantly share code, notes, and snippets.

@dvrajan
Created November 5, 2014 04:12
Show Gist options
  • Save dvrajan/fbc4fc60704ce1aeb99c to your computer and use it in GitHub Desktop.
Save dvrajan/fbc4fc60704ce1aeb99c to your computer and use it in GitHub Desktop.
"""
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' % REPO ) + '?state=closed&per_page=1000'
AUTH = (GITHUB_USER, GITHUB_PASSWORD)
def write_issues(r):
"output a list of issues to csv"
if not r.status_code == 200:
raise Exception(r.status_code)
for issue in r.json():
labels = ','.join([label['name'] for label in issue['labels']])
csvout.writerow([issue['number'], issue['title'].encode('utf-8'), issue['body'].encode('utf-8'), labels])
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', 'labels'))
write_issues(r)
ISSUES_FOR_REPO_URL = ('https://api.github.com/repos/%s/issues' % REPO ) + '?state=closed&page=2&per_page=1000'
r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH)
csvout = csv.writer(open(csvfile, 'awb'))
write_issues(r)
ISSUES_FOR_REPO_URL = ('https://api.github.com/repos/%s/issues' % REPO ) + '?state=open&per_page=1000'
r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH)
csvout = csv.writer(open(csvfile, 'awb'))
write_issues(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment