pullrequest_contributors.py
1 import sys 2 import json 3 import urllib 4 import argparse 5 from collections import defaultdict 6 7 8 auth = "?client_id=&client_secret=" 9 10 11 repo = sys.argv[1] 12 pr = sys.argv[2] 13 link_pulls_commits = "https://api.github.com/repos/" + repo + "/pulls/" + pr + "/commits" +auth 14 points = defaultdict(int) 15 commits = json.load(urllib.urlopen(link_pulls_commits)) 16 for commit in commits: 17 if(commit['url']): 18 link_commit = json.dumps(commit['url'])[1:-1] +auth 19 _commit = json.load(urllib.urlopen(link_commit)) 20 author = json.dumps(_commit['author']['login'])[1:-1] 21 points[author] += int(json.dumps(_commit['stats']['total'])) 22 print points.items()