-
-
Save lauraGgit/305d9aeb749eb8075030 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({"link": issue['html_url'], "number": issue["number"], "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, ['issue_link', 'issue_id', 'title', 'body']) | |
writer.writeheader() | |
for issue in issues: | |
writer.writerow({'issue_link': issue["link"], 'issue_id': issue['number'],'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