Forked from unbracketed/export_repo_issues_to_csv.py
Last active
April 15, 2016 13:55
-
-
Save brittharr/898c3c949d6c9a07d698 to your computer and use it in GitHub Desktop.
Export Issues from Github repo to CSV (API v3)
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
""" | |
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 | |
ARGS = "?state=all&per_page=100" | |
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'] | |
labelString = '' | |
for label in labels: | |
labelString += label['name'] + '|' | |
csvout.writerow([issue['number'], labelString[:-1], issue['title'].encode('utf-8'), issue['body'].encode('utf-8'), issue['created_at'], issue['updated_at'], issue['closed_at']]) | |
r = requests.get(ISSUES_FOR_REPO_URL + ARGS, auth=AUTH) | |
csvfile = '%s-issues.csv' % (REPO.replace('/', '-')) | |
csvout = csv.writer(open(csvfile, 'wb')) | |
csvout.writerow(('id', 'Labels', 'Title', 'Body', 'Created At', 'Updated At', 'Closed At')) | |
write_issues(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment