Skip to content

Instantly share code, notes, and snippets.

@blakesmith
Created July 4, 2010 02:00
Show Gist options
  • Select an option

  • Save blakesmith/463016 to your computer and use it in GitHub Desktop.

Select an option

Save blakesmith/463016 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
#
# Quick and dirty script to extract some statistics about
# Rails core contributers.
#
# Usage: git_core_stats <path to rails git project>
# Example: git_core_stats ~/code/rails
#
# OR
#
# Example: cd ~/code/rails; /usr/local/bin/git_core_stats
class GitStats
def initialize(directory=nil)
@author = @committer = 0
@contributers = []
@directory = directory
@core_members = [
"David Heinemeier Hansson",
"Jeremy Kemper",
"Michael Koziarski",
"Pratik Naik",
"Joshua Peek",
"Yehuda Katz",
"José Valim",
"Carl Lerche"
]
end
def reset!
@author = @committer = 0
@contributers = []
end
def run
@core_members.each {|c| reset!; stats(c) }
end
def stats(name)
@directory ||= "."
command = "cd #{@directory}; git --no-pager log --format='%cn:%an' --committer='#{name}'"
results = `#{command}`
print_results(name, split_entries(results))
end
def split_entries(results)
results.split("\n").each do |line|
entry = line.split(":")
if same?(entry)
@author += 1
else
@committer += 1
end
@contributers << entry.last unless has_contributer?(entry.last)
end
{
:total => @author + @committer,
:author => @author,
:author_percentage => (@author/(@author+@committer).to_f*100),
:committer => @committer,
:committer_percentage => (@committer/(@author+@committer).to_f*100)
}
end
def has_contributer?(contributer)
@contributers.include?(contributer)
end
def same?(entry)
entry.first == entry.last
end
def print_results(name, results)
puts "---------"
puts "Git status for: #{name}\n"
puts "Total commits: #{results[:total]}"
puts "Commits by author: #{results[:author]} (#{results[:author_percentage]}%)\n"
puts "Commits by someone else: #{results[:committer]} (#{results[:committer_percentage]}%)"
puts "Total contributers: #{@contributers.count}"
end
end
GitStats.new(ARGV.first).run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment