Skip to content

Instantly share code, notes, and snippets.

@Earlopain
Created August 21, 2023 10:39
Show Gist options
  • Save Earlopain/5b10a874fb49a360b6d444d3ce17a8dd to your computer and use it in GitHub Desktop.
Save Earlopain/5b10a874fb49a360b6d444d3ce17a8dd to your computer and use it in GitHub Desktop.
require "json"
require "tempfile"
require "open3"
CUTOFF_COMMIT = "00d783fd87b21f17245a39980a9933bf128ff845"
config = Tempfile.new
config << File.read(".rubocop.yml").sub("inherit_from: .rubocop_todo.yml", "")
config.close
loop do
current_commit = `git rev-parse HEAD`.strip
raise StandardError, "rev-parse failed" if current_commit == ""
current_commit_timestamp = `git show -s --format=%ct`.strip
filename = "stats/#{current_commit_timestamp}-#{current_commit}.json"
if File.exist?(filename)
puts "Skipping #{current_commit}"
else
puts "Analyzing commit #{current_commit}"
json_tmp = Tempfile.new
system("rubocop --format autogenconf --format json --out #{json_tmp.path} --config #{config.path}")
json = JSON.parse(File.read(json_tmp.path))
json["summary"]["commit"] = current_commit
json["summary"]["commit_timestamp"] = current_commit_timestamp
File.write(filename, JSON.pretty_generate(json["summary"]))
end
previous_commit = `git log --pretty=format:"%H" -2`.split("\n").last
system("git checkout #{previous_commit}", exception: true)
break if current_commit == CUTOFF_COMMIT
end
puts "DONE!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment