Skip to content

Instantly share code, notes, and snippets.

@fkztw
Last active December 27, 2017 12:41
Show Gist options
  • Save fkztw/94be5759d2f13bfdcdd485feff2be3e6 to your computer and use it in GitHub Desktop.
Save fkztw/94be5759d2f13bfdcdd485feff2be3e6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from pprint import pprint
# Make sure you've installed github3.py via `pip install --pre github3.py`
from github3 import login
MY_GITHUB_USERNAME = ""
# Visit https://github.com/settings/tokens to create a token if you don't have.
# Check "repo" permission
MY_GITHUB_TOKEN = ""
TARGET_ORGNIZATION_NAME = ""
user = login(token=MY_GITHUB_TOKEN)
org = user.organization(TARGET_ORGNIZATION_NAME)
my_stats = []
for repo in org.repositories():
for contribution in repo.contributor_statistics():
if MY_GITHUB_USERNAME in repr(contribution.author):
print(repo.name, contribution.total)
my_stats.append((repo.name, contribution.total))
print("")
print('=' * 80)
print("")
print("GitHub username: {}".format(MY_GITHUB_USERNAME))
print("Target GitHub organization: {}".format(TARGET_ORGNIZATION_NAME))
print("Total contributed repos: {}".format(len(my_stats)))
print("Total commits: {}".format(sum(commits for repo, commits in my_stats)))
my_stats_desc_sorted = sorted(my_stats, key=lambda x: x[1], reverse=True)
print("Repo and commits:")
pprint(my_stats_desc_sorted)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment