Created
May 16, 2017 18:53
-
-
Save ikonst/91f9e0935ad9643b792ea0d9397a6021 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
from github import Github | |
from csv import DictWriter | |
# Generate on https://github.com/settings/tokens | |
TOKEN = '<REDACTED>' | |
ORG = 'lyft' | |
AUTHOR = '<github username here>' | |
g = Github(login_or_token=TOKEN) | |
org = g.get_organization(ORG) | |
repos = org.get_repos() | |
f = open('commits.csv', 'w') | |
csv = DictWriter(f, [ | |
'date', | |
'repo', | |
'subject', | |
'additions', | |
'deletions', | |
'total', | |
'link', | |
]) | |
csv.writeheader() | |
for repo in repos: | |
print('Processing repo {}'.format(repo.name)) | |
for commit in repo.get_commits(author=AUTHOR): | |
lines = commit.commit.message.split('\n') | |
row = { | |
'date': commit.commit.author.date, | |
'repo': repo.name, | |
'subject': lines[0], | |
'additions': commit.stats.additions, | |
'deletions': commit.stats.deletions, | |
'total': commit.stats.total, | |
'link': u'https://www.github.com/{org_name}/{repo_name}/commit/{sha}'.format( | |
org_name=org.name, | |
repo_name=repo.name, | |
sha=commit.sha, | |
), | |
} | |
utf8_row = {k: (v.encode('utf-8') if isinstance(v, unicode) else v) for k, v in row.items()} | |
csv.writerow(utf8_row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment