lib/attractor/calculator.rb in attractor-0.4.3 vs lib/attractor/calculator.rb in attractor-0.5.0
- old
+ new
@@ -27,10 +27,27 @@
churn[:churn][:changes].map do |change|
flogger = Flog.new(all: true)
flogger.flog(change[:file_path])
complexity = flogger.total_score
- Value.new(file_path: change[:file_path], churn: change[:times_changed], complexity: complexity)
+ details = flogger.totals
+ Value.new(file_path: change[:file_path],
+ churn: change[:times_changed],
+ complexity: complexity,
+ details: details,
+ history: git_history_for_file(file_path: change[:file_path]))
+ end
+ end
+
+ private
+
+ def git_history_for_file(file_path:, limit: 10)
+ history = `git log --oneline --follow -n #{limit} -- #{file_path}`
+ history.split("\n")
+ .map do |log_entry|
+ log_entry.partition(/\A(\S+)\s/)
+ .map(&:strip)
+ .reject(&:empty?)
end
end
end
end