Skip to content

Instantly share code, notes, and snippets.

@Indigo744
Created May 30, 2017 15:21
Show Gist options
  • Save Indigo744/1205db711dd9e12d2972b09715c6ca35 to your computer and use it in GitHub Desktop.
Save Indigo744/1205db711dd9e12d2972b09715c6ca35 to your computer and use it in GitHub Desktop.
Find all contributors of a specific Github repository
# -*- coding: utf-8 -*-
#
# Find all contributors of a specific Github repository
#
# Tested with Python 2.7 / Windows 10
#
# Usage: python get_contributors.py PHPOffice/PHPExcel
#
# Author: Indigo744
# Date: 2017-05-30
# Public domain
import sys
import json
import urllib2
from datetime import datetime
# Separator to use to delimit fields
SEPARATOR = ';'
# Filter user with less commits (0 or 1 == ALL)
MEANINGFUL_COMMITS_VALUE = 1
# Filter user with less addition (0 == ALL)
MEANINGFUL_ADDITION_VALUE = 10
github_repo = sys.argv[1]
print "Checking %s" % github_repo
print ""
json_response = json.load(urllib2.urlopen("https://api.github.com/rate_limit"))
print "Rate limiter: %d / %d (reset @ %s)" % (json_response['rate']['remaining'],
json_response['rate']['limit'],
datetime.utcfromtimestamp(json_response['rate']['reset']))
print ""
try:
json_response = json.load(urllib2.urlopen("https://api.github.com/repos/%s/stats/contributors" % github_repo))
except urllib2.HTTPError, e:
json_response = json.load(e.fp)
print json_response['message']
exit()
contributors = {}
print "Found %d contributors" % len(json_response)
print ""
for contributor in json_response:
login = unicode(contributor['author']['login'])
contributors[login] = {
'addition': 0,
'deletion': 0,
'commits': 0
}
for week in contributor['weeks']:
contributors[login]['addition'] += int(week['a'])
contributors[login]['deletion'] += int(week['d'])
contributors[login]['commits'] += int(week['c'])
if contributors[login]['addition'] < MEANINGFUL_ADDITION_VALUE:
print "%s doesn't have enough addition (%d)" % (login, contributors[login]['addition'])
del(contributors[login])
elif contributors[login]['commits'] < MEANINGFUL_COMMITS_VALUE:
print "%s doesn't have enough commits (%d)" % (login, contributors[login]['commits'])
del(contributors[login])
print "Found %d contributors left" % len(contributors)
print ""
print SEPARATOR.join(['login', 'page', 'contribution'])
for login, contrib in contributors.iteritems():
print SEPARATOR.join([
login,
"https://github.com/%s" % login,
'%d commits / %d ++ / %d --' % (contrib['commits'], contrib['addition'], contrib['deletion'])
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment