namespace :metricks do CHURN_DIR = File.join(Metricks::BASE_DIRECTORY, 'churn') desc "Which files change the most" task :churn do date_range, minimum_churn_count = churn_options() svn_logs = `svn log #{date_range} --verbose`.split(/\n/).select {|line| line.strip =~ /^[A,M]/} changes = {} svn_logs.each do |line| line.strip =~ /^[A,M] (.*)/ changes[$1] ? changes[$1] += 1 : changes[$1] = 1 end write_churn_file(changes.reject {|file, change_count| change_count < minimum_churn_count}) system("open #{CHURN_DIR}/index.html") if PLATFORM['darwin'] end def churn_options options = defined?(CHURN_OPTIONS) ? CHURN_OPTIONS : {} if options[:start_date] require File.dirname(__FILE__) + '/../../../../config/environment' date_range = "--revision {#{options[:start_date].call.strftime('%Y-%m-%d')}}:{#{Time.now.strftime('%Y-%m-%d')}}" else date_range = "" end minimum_churn_count = options[:minimum_churn_count] ? options[:minimum_churn_count] : 5 return date_range, minimum_churn_count end def write_churn_file changes FileUtils.mkdir_p(CHURN_DIR, :verbose => false) unless File.directory?(CHURN_DIR) File.open("#{CHURN_DIR}/index.html", "w+") do |file| file << CHURN_FILE_BEGINING changes.to_a.sort {|x,y| y[1] <=> x[1]}.each do |change| file << "#{change[0]}#{change[1]}\n" end file << CHURN_FILE_END end end CHURN_FILE_BEGINING = <<-EOS Source Control Churn Results

Source Control Churn Results

EOS CHURN_FILE_END = <<-EOS
File PathTimes Changed
EOS end