-
-
Save msztolcman/1457687 to your computer and use it in GitHub Desktop.
Export GitHub issues and comments to a csv files
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
#!/usr/bin/env python -tt | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function, unicode_literals | |
import os, os.path | |
import sys | |
import re | |
import time | |
from pprint import pprint | |
import csv | |
from github2.client import Github | |
# api settings for github | |
git_username = '' | |
git_api_token = '' | |
git_repo = '' | |
# csv name | |
csv_issues_name = "github_issues.csv" | |
csv_cmnts_name = "github_cmnts.csv" | |
def run_csv(): | |
""" | |
Export github issues into a csv format | |
""" | |
issues_csv = csv.writer(open(csv_issues_name, 'wb'), delimiter=b',') | |
cmnts_csv = csv.writer(open(csv_cmnts_name, 'wb'), delimiter=b',') | |
github = Github(username=git_username, api_token=git_api_token) | |
# csv issues headers | |
issues_headers = [ | |
'id', | |
'title', | |
'body', | |
'state', | |
'creator', | |
'labels', | |
'created_at', | |
'updated_at', | |
'closed_at', | |
] | |
# write header rows | |
issues_csv.writerow(issues_headers) | |
# csv comments headers | |
cmnts_headers = [ | |
'id', | |
'body', | |
'user', | |
'gravatar_id', | |
'created_at', | |
'updated_at', | |
] | |
# write header rows | |
cmnts_csv.writerow (cmnts_headers) | |
# get the git issues and write the rows to the csv | |
for issue_state in ('open', 'closed', ): | |
git_issues = github.issues.list(git_repo, state=issue_state) | |
for git_issue in git_issues: | |
print (git_issue.title) | |
labels = ','.join(git_issue.labels) | |
# alot of these are blank because they are not really | |
# needed but if you need them just fill them out | |
issue = [ | |
git_issue.number, | |
git_issue.title.encode('utf8'), | |
git_issue.body.encode('utf8'), | |
git_issue.state, | |
git_issue.user, | |
labels, | |
git_issue.created_at, | |
git_issue.updated_at, | |
git_issue.closed_at, | |
] | |
issues_csv.writerow(issue) | |
for git_cmnt in github.issues.comments (git_repo, git_issue.number): | |
print (' ' + git_cmnt.user + ' at ' + git_cmnt.created_at.strftime ('%Y-%m-%d %H:%M:%S')) | |
cmnt = [ | |
git_cmnt.id, | |
git_cmnt.body.encode ('utf8'), | |
git_cmnt.user, | |
git_cmnt.gravatar_id, | |
git_cmnt.created_at, | |
git_cmnt.updated_at, | |
] | |
cmnts_csv.writerow(cmnt) | |
time.sleep (1) | |
if __name__ == '__main__': | |
run_csv() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/gavinr/github-csv-tools