""" 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/{}/issues'.format(REPO) 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 csvout.writerow([issue['number'], issue['title'].encode('utf-8'), issue['html_url']]) r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH) csvfile = '{}-issues.csv'.format(REPO.replace('/', '-')) csvout = csv.writer(open(csvfile, 'wb')) csvout.writerow(('id', 'Title', 'URL')) 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: r = requests.get(pages['next'], auth=AUTH) write_issues(r) if pages['next'] == pages['last']: break