Skip to content

Instantly share code, notes, and snippets.

@NakedFerret
Last active March 9, 2018 17:00
Show Gist options
  • Save NakedFerret/2f87ff66578816d230eba61417f9e1ff to your computer and use it in GitHub Desktop.
Save NakedFerret/2f87ff66578816d230eba61417f9e1ff to your computer and use it in GitHub Desktop.
Python script that queries git to list contributors to your files. Can ignore people and detect multiple username for one contributor. Outputs CSV
#!/usr/bin/env python
import subprocess
# Inspiration: https://stackoverflow.com/a/11740682
r = subprocess.check_output(['git','ls-tree','-r','--name-only','origin/master','./'])
files = r.split();
ignoredPeeps = set(['Laima Tazmin', 'Cara Warner', 'Patty Delgado', 'Matt Anderson', 'r29bot'])
nameMap = {
'carlo.francisco@refinery29.com': 'Carlo Francisco',
'jcfrancisco': 'Carlo Francisco',
'Jen': 'Jennifer Calloway',
'josipherceg': 'Josip Herceg',
'josip.herceg@refinery29.com': 'Josip Herceg',
'Liyan.Tang': 'Liyan Tang',
'liyantang': 'Liyan Tang',
'patty.delgado@refinery29.com': 'Patty Delgado',
'johnnyshankman': 'Johnny Shankman',
'Maggie Love & Noah Lemen': 'Noah Lemen',
}
for f in files:
peeps = subprocess.check_output([
'git', 'log', '--follow', '--pretty=format:%an', '--', f
])
# One peep per line
peeps = peeps.split('\n')
# Some people use multiple accounts. Consolidate to one name
peeps = map(lambda x: nameMap.get(x, x), peeps)
# Take out duplicates and ignoredPeeps
peeps = set(peeps) - ignoredPeeps
peeps = list(peeps)
peeps.sort()
print "{0},{1},{2}".format(f, len(peeps), ','.join(peeps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment