public
Created

Examine files and review git history to determine what percentage of the files was written by a particular author

  • Download Gist
find_by_author.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#!/usr/bin/env ruby
 
author = ARGV.shift
dir = ARGV.shift || "."
BlamedFile = Struct.new(:file, :lines, :blamed_lines, :percent)
files = []
all_files = Dir.glob("#{dir}/**/*")
puts "Examining #{all_files.size} files:"
all_files.each do |file|
next if File.directory?(file)
next unless File.readable?(file)
lines = File.readlines(file).size
next if lines == 0
print "."
$stdout.flush
blamed_lines = `git blame #{file} | grep "#{author}"`.split("\n").size
files << BlamedFile.new(file, lines, blamed_lines, blamed_lines / lines.to_f)
end
 
puts ""
 
files.sort_by{|f| f.percent}.reverse.each do |f|
next unless f.blamed_lines > 1
next unless f.lines > 10
puts "%3.0f%% of %d lines - %s" % [f.percent * 100, f.lines, f.file]
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.