Last active
December 12, 2016 19:30
-
-
Save vdavez/9ba3d3cadb8ebe8739af to your computer and use it in GitHub Desktop.
gh-issues-to-csv.py
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 requests | |
import json | |
import sys | |
import csv | |
def getIssues(url): | |
""" | |
@param {url} The url of the github issues | |
@return the json object | |
""" | |
r = requests.get(url) | |
if r.status_code != 200: | |
raise "There call to the GitHub issues API failed" | |
return r.json() | |
def cleanIssues(issues): | |
""" | |
@param {issues} the json object | |
@returns {issues} with *only* the Title and Body | |
""" | |
response = [] | |
for issue in issues: | |
response.append({"title": issue["title"], "body": issue["body"]}) | |
return response | |
def dumpToCSV(issues): | |
""" | |
@param {issues} the json object | |
@returns True when complete | |
""" | |
writer = csv.DictWriter(sys.stdout, ['title', 'body']) | |
writer.writeheader() | |
for issue in issues: | |
writer.writerow({'title': issue["title"], 'body': issue["body"]}) | |
return True | |
if __name__ == "__main__": | |
url = "https://api.github.com/repos/18F/bpa-fedramp-dashboard/issues?state=open" | |
issues = getIssues(url) | |
cleaned = cleanIssues(issues) | |
dumpToCSV(cleaned) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated the script to have the script write out the github url id/ and the issue id for the script:
25
response.append({"link": issue['html_url'], "number": issue["number"], "title": issue["title"], "body": issue["body"]})
34
writer = csv.DictWriter(sys.stdout, ['issue_link', 'issue_id', 'title', 'body'])
37
writer.writerow({'issue_link': issue["link"], 'issue_id': issue['number'],'title': issue["title"], 'body': issue["body"]})
https://gist.github.com/lauraGgit/305d9aeb749eb8075030/revisions