Last active
July 31, 2022 11:08
-
-
Save yob/081d3f9bbaa0317523360e54b184f872 to your computer and use it in GitHub Desktop.
Calculate libyear for a ruby project over time, for charting progress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To generate the input file, I ran this: | |
# | |
# git log --merges --date-order --pretty="format:%h%d %aI" > first-commit-per-month.txt | |
# | |
# ... and then manually edited the file to have only the first commit per month. it'd | |
# be neat to geneate the list of target commits automatically. | |
# | |
# Note: this doesn't work with upstreamn libyears-bundler, because https://github.com/jaredbeck/libyear-bundler/issues/4 | |
# However, my very hacky fork can do it: https://github.com/yob/libyear-bundler | |
File.open("first-commit-per-month.txt", "r") do |file| | |
file.each_line do |line| | |
sha, timestamp = *line.split(" ") | |
date = timestamp[0,10] | |
datetime = Time.iso8601(timestamp) | |
# print commit sha and timestamp | |
puts "********************************" | |
puts "#{sha},#{date}" | |
puts "********************************" | |
# ensure we have a clean working directory | |
system("git reset --hard > /dev/null") | |
# checkout the target git sha | |
system("git checkout #{sha} > /dev/null") | |
# append libyear-bundler to the Gemfile and then run bundle to update Gemfile.lock | |
system("echo 'gem \"libyear-bundler\" , github: \"yob/libyear-bundler\"' >> Gemfile") | |
Bundler.with_unbundled_env do | |
system("bundle > /dev/null") | |
end | |
# Run libyear to print the aggregate number of years this project is behind | |
system("libyear-bundler --cache=/usr/local/bundle/libyear.yml --libyears --grand-total --max-time=\"#{datetime.iso8601}\"") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment