-
-
Save tleish/b7271f1dbd43b1db873476b4538c4af8 to your computer and use it in GitHub Desktop.
A script that collects and prints info about the age of all ruby gems in your project, see https://dev.to/borama/how-old-are-dependencies-in-your-ruby-project-3jia
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
#!/bin/env ruby | |
# | |
# Collects info about the age of all gems in the project | |
# | |
require "json" | |
require "date" | |
# Dir.chdir '...' | |
bundle = `bundle list` | |
yearly_stats = {} | |
bundle.split(/\n/).each do |line| | |
next unless line =~ /\s+\*\s+[^ ]+\s+\(.*\)/ | |
gem_name, gem_version = /\s+\*\s+([^ ]+)\s+\((.*)\)/.match(line).to_a[1..-1] | |
begin | |
gem_releases = JSON.parse(`curl -s https://rubygems.org/api/v1/versions/#{gem_name}.json`) | |
gem = gem_releases.find { |gem_release| gem_release['number'] == gem_version } | |
release_date = Date.parse(gem["built_at"]).to_date | |
puts "Current: #{gem_name}, #{gem['number']}, #{release_date.strftime("%Y-%m-%d")}" | |
release_year = release_date.strftime("%Y") | |
yearly_stats[release_year] ||= {} | |
yearly_stats[release_year][:current_count] ||= 0 | |
yearly_stats[release_year][:current_gems] ||= [] | |
yearly_stats[release_year][:current_count] += 1 | |
yearly_stats[release_year][:current_gems] << gem_name | |
gem = gem_releases.find { |gem_release| gem_release['prerelease'] == false } | |
release_date = Date.parse(gem["built_at"]).to_date | |
puts "Latest: #{gem_name}, #{gem['number']}, #{release_date.strftime("%Y-%m-%d")}" unless gem['number'] == gem_version | |
release_year = release_date.strftime("%Y") | |
yearly_stats[release_year] ||= {} | |
yearly_stats[release_year][:latest_count] ||= 0 | |
yearly_stats[release_year][:latest_gems] ||= [] | |
yearly_stats[release_year][:latest_count] += 1 | |
yearly_stats[release_year][:latest_gems] << gem_name | |
puts '' | |
rescue => e | |
puts "Current: #{gem_name}, #{gem_version}, ???\n\n" | |
end | |
end | |
puts | |
puts "Yearly summary:" | |
puts 'Year, Current, Latest, Current Gems, Latest Gems, Diff' | |
yearly_stats.sort.each do |year, data| | |
puts [ | |
year, | |
data[:current_count].to_i, | |
data[:latest_count].to_i, | |
Array(data[:current_gems]).join(' '), | |
Array(data[:latest_gems]).join(' '), | |
(Array(data[:latest_gems]) - Array(data[:current_gems])).join(' ') | |
].join(", ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment