Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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