Skip to content

Instantly share code, notes, and snippets.

@vdavez
Last active December 12, 2016 19:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vdavez/9ba3d3cadb8ebe8739af to your computer and use it in GitHub Desktop.
Save vdavez/9ba3d3cadb8ebe8739af to your computer and use it in GitHub Desktop.
gh-issues-to-csv.py
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)
@lauraGgit
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment