Created
August 10, 2013 04:48
-
-
Save KevinGreene/6199099 to your computer and use it in GitHub Desktop.
Export github issues to pivotal Some minor updates to https://gist.github.com/unbracketed/3380407 to put it in a more typical Pivotal Tracker import format
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
| import csv | |
| import requests | |
| GITHUB_USER = 'REDACTED' | |
| GITHUB_PASSWORD = 'REDACTED' | |
| REPO = 'USER/REPO' # format is username/repo | |
| ISSUES_FOR_REPO_URL = 'https://api.github.com/repos/%s/issues' % 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: | |
| # Toggle this off if you don't want all the output | |
| print(issue) | |
| csvout.writerow([issue['title'].encode('utf-8'), issue['html_url'], 'Feature']) | |
| r = requests.get(ISSUES_FOR_REPO_URL, auth=AUTH) | |
| csvfile = '%s-issues.csv' % (REPO.replace('/', '-')) | |
| csvout = csv.writer(open(csvfile, 'wb')) | |
| csvout.writerow(('Story', 'Description', 'Story Type')) | |
| 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 | |
| pages['next'] = pages['next'][:-1] + str((int(pages['next'][-1]) + 1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment