Skip to content

Instantly share code, notes, and snippets.

@mhoye
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhoye/9072577 to your computer and use it in GitHub Desktop.
Save mhoye/9072577 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from mercurial import ui, hg, cmdutil, match
from collections import defaultdict
import json
import sys
if len (sys.argv) == 1:
print( "\nThis script determines contributor numbers between a certain range of commits." +
"\nOrder of arguments is important:" +
"\n\n contrib.py [local mercurial repo] [employee emails (flat)]\n")
exit()
repo = hg.repository( ui.ui(), sys.argv[1] )
employees = {}
res_emp = list()
res_vol = list()
res_tot = list()
res_emp_cont = list()
res_vol_cont = list()
res_tot_cont = list()
res_vol_perc = list()
res_leverage_people = list()
res_leverage_patches = list()
hg_revnums =[ 113672, 117931, 122315, 126855, 131682, 136272, 141367, 147372,
152943, 159494, 166629, 173936, 180520, 187591, 195409, 202941,
210096, 217976, 223387, 230280]
def sanitize(s):
return s.replace(u"\u201c", '"').replace(u"\u201d", '"').replace(u"\u2018", "'").replace(u"\u2019", "'")
emails = list()
with open(sys.argv[2]) as f:
lines = f.readlines()
if not lines[-1].split():
lines.pop()
emails += map(lambda x: x.split()[0], lines)
def count_contribs(from_rev, to_rev):
authors = defaultdict(int)
pats = ()
opts = {'rev': [to_rev + ':' + from_rev]}
matchfn = match.match(repo.root, repo.getcwd(), pats)
def prep(ctx, fns):
rev = ctx.rev()
if len(repo.changelog.parentrevs(rev)) == 2:
return
for rev in cmdutil.walkchangerevs(repo, matchfn, opts, prep):
author = str(rev.user()).decode('utf-8')
authors[author] += 1
employee_authors = set()
volunteer_authors = set()
partials = set()
for author in authors.keys(): #All entries in authors.keys and emails should be unique at this point.
# check to see if it's an @mozilla address
if 0 < author.find("@mozilla."): # might be a problem of people own mozilla.whoever.wherever domains
employee_authors.add(author)
# print("Employee: " + author).encode('utf-8')
else:
# ok, now see if it's on the list of known bugmail or employee addresses
for email in emails:
if author in email:
employee_authors.add(author)
# print("Employee: " + author).encode('utf-8')
break
# OK, welp. If we're here, they're probably a contributor.
else:
volunteer_authors.add(author)
# print("Contributor: " + author).encode('utf-8')
emp_contributions = sum(map(lambda x: authors[x], filter(lambda x: x in employee_authors, authors)))
vol_contributions = sum(map(lambda x: authors[x], filter(lambda x: x in volunteer_authors, authors)))
res_emp.append( len(employee_authors) )
res_vol.append( len(volunteer_authors) )
res_tot.append( len(employee_authors) + len(volunteer_authors) )
res_emp_cont.append(emp_contributions)
res_vol_cont.append(vol_contributions)
res_tot_cont.append(emp_contributions + vol_contributions)
res_vol_perc.append(100 * vol_contributions / (emp_contributions + vol_contributions) )
res_leverage_people.append(float(len(volunteer_authors)) / float(len(employee_authors)))
res_leverage_patches.append( float(vol_contributions) / float(len(employee_authors)))
for c in range(1, len(hg_revnums) - 1) :
count_contribs(str(hg_revnums[c-1]+1), str(hg_revnums[c]) )
print "employees: " + str(res_emp) + ","
print "volunteers: " + str(res_vol) + ","
print "total: " + str(res_tot) + ","
print "employee_commits: " + str(res_emp_cont) + ","
print "volunteer_commits: " + str(res_vol_cont) + ","
print "total_commits: " + str(res_tot_cont) + ","
print "volunteer_commit_percentage: " + str(res_vol_perc) + ","
print "leverage_people: " + str(res_leverage_people) + ","
print "leverage_patches: " + str(res_leverage_patches)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment