Created
March 2, 2017 18:37
-
-
Save csmoore/e02c109713a3caeb023fd0b0cd0ab1c1 to your computer and use it in GitHub Desktop.
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
# Basic PyGithub Example - Example/test of using PyGithub (Python Github API) | |
# Repo(s) Open Issues List to CSV | |
# requires PyGithub (and python-jose) : | |
# pip install PyGithub | |
# -or- conda install -c conda-forge --name yourenvname pygithub | |
import os | |
import csv | |
from github import Github | |
default_output_path = os.path.dirname(__file__) | |
# TODO: you must edit these for the org/user + repos you want to list | |
# and if you want to change the output csv file name | |
csv_file = os.path.normpath(os.path.join(default_output_path, 'github_issues.csv')) | |
org_name = 'Esri' # org/user name | |
repo_names = ['visibility-addin-dotnet', 'distance-direction-addin-dotnet'] | |
def make_issue_title(repo_name, issue): | |
return "%s - #%s : %s" % (repo_name, issue.number, issue.title) | |
def main(): | |
# Set up CSV | |
f_out = open(csv_file, 'w') # Note: 'wb' for py2 | |
csv_writer = csv.writer(f_out, dialect='excel', delimiter=',', lineterminator='\n') | |
header = ['Item #', 'Repo Name', 'Issue Title', 'Issue Number', 'Issue URL', 'Issue Create Date', 'Issue Labels', 'Issue Description'] | |
csv_writer.writerow(header) | |
# Set up PyGithub | |
# Note: Need to add 'user', 'pw' here if hitting private repo -or- if you don't want to be request-limited | |
g = Github() | |
org = g.get_organization(org_name) | |
for repo_name in repo_names: | |
print('Processing Repo: ' + repo_name) | |
repo = org.get_repo(repo_name) | |
repo_full_name = repo.full_name | |
issues = repo.get_issues(state='open') | |
count = 0 | |
for issue in issues: | |
count += 1 | |
print('Processing Issue #' + str(count)) | |
labels = ';'.join([label.name for label in issue.labels]) | |
row = [str(count), repo_full_name, make_issue_title(repo_full_name, issue), \ | |
issue.number, issue.html_url, issue.created_at.strftime("%Y-%m-%d"), \ | |
labels, issue.body] | |
csv_writer.writerow(row) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment