Created
December 6, 2016 16:15
-
-
Save flipace/1880922b89e034e2636cffa7b21f5660 to your computer and use it in GitHub Desktop.
Calculate commit numbers accross all git projects in/below the current directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import subprocess | |
import operator | |
from slugify import slugify | |
import datetime | |
now = datetime.datetime.now() | |
allSummarries = [] | |
ignoreNames = ["put names to ignore in here"] | |
analyzedCommits = [] | |
duplicatedCommits = 0 | |
names = {} | |
repos = {} | |
# traverse root directory, and list directories as dirs and files as files | |
for root, dirs, files in os.walk("."): | |
path = root.split('/') | |
if ".git" in dirs: | |
print "Analyzing: ", os.path.basename(root); | |
try: | |
x = subprocess.check_output(["git log --pretty='format:%H\t%an' --since='" + str(now.year) + "-01-01'"], cwd=root, shell=True) | |
summaries = x.split('\n') | |
repos[os.path.basename(root)] = 0 | |
for summary in summaries: | |
splitted = summary.split('\t') | |
if len(splitted) > 1: | |
commitHash = splitted[0].strip() | |
name = splitted[1].strip() | |
slug = slugify(name, separator="") | |
if commitHash in analyzedCommits: | |
duplicatedCommits += 1 | |
else: | |
repos[os.path.basename(root)] += 1 | |
if name not in ignoreNames: | |
analyzedCommits.append(commitHash) | |
if slug in names: | |
names[slug]['count'] = names[slug]['count'] + 1 | |
else: | |
names[slug] = { 'name': name, 'count': 1 } | |
except subprocess.CalledProcessError, e: | |
print "Error:\n", e.output | |
else: | |
continue; | |
sorted_repos = sorted(repos.items(), key=operator.itemgetter(1), reverse=True) | |
sorted_names = sorted(names.items(), key=operator.itemgetter(1), reverse=True) | |
print '\n' | |
print '-----------------' | |
print '-----REPOS-------' | |
print '-----------------' | |
for repo in sorted_repos: | |
print str(repo[1]) + ":" + repo[0] | |
print '-----------------' | |
print '-----USERS-------' | |
print '-----------------' | |
for user in sorted_names: | |
user = user[1] | |
name = user['name'] | |
count = user['count'] | |
if count > 30: | |
print str(count) + ':', name | |
print '-----------------' | |
print '-----------------' | |
print "Ignored " + str(duplicatedCommits) + " duplicated commits" | |
print '-----------------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment