Created
November 28, 2013 18:43
-
-
Save andersonvom/7696537 to your computer and use it in GitHub Desktop.
Gather statistics on GIT projects regarding number of commits, lines of code (insertions/deletions), and files changed.
This file contains hidden or 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
DATE="2013-10-28 00:00:00" | |
METRIC=:total_loc | |
TEAM=[ | |
'Team Member #1', | |
'Team Member #2', | |
'Team Member #3', | |
# ... | |
] | |
def match_stat(str, stat) | |
(str.match("(\\d+) #{stat}") or [])[1].to_i | |
end | |
stats = {} | |
TEAM.each do |member| | |
print "." | |
stats[member] = { | |
files: 0, | |
insertions: 0, | |
deletions: 0, | |
total_loc: 0, | |
commits: 0, | |
} | |
logs = `git log --stat --since="#{DATE}" --author="#{member}" \| grep -e 'files\\?'`.split("\n") | |
logs.each do |log| | |
stats[member][:files] += match_stat(log, 'file') | |
stats[member][:insertions] += match_stat(log, 'insertions') | |
stats[member][:deletions] += match_stat(log, 'deletions') | |
stats[member][:total_loc] += match_stat(log, 'insertions') + match_stat(log, 'deletions') | |
stats[member][:commits] += 1 | |
end | |
end | |
puts | |
final_results = stats.sort_by { |member, results| results[METRIC] }.reverse | |
final_results.each do |member, results| | |
puts member | |
puts "#{"%4d" % results[:files]} files changed " + | |
"#{"%4d" % results[:insertions]} insertions " + | |
"#{"%4d" % results[:deletions]} deletions " + | |
"#{"%4d" % results[:total_loc]} total lines of code " + | |
"#{"%4d" % results[:commits]} commits " | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment