Skip to content

Instantly share code, notes, and snippets.

@landovsky
Created September 8, 2020 09:48
Show Gist options
  • Save landovsky/68df74828cf413b3e5036ca0db107948 to your computer and use it in GitHub Desktop.
Save landovsky/68df74828cf413b3e5036ca0db107948 to your computer and use it in GitHub Desktop.
Check last built date of gems in your Gemfile to find out how old is the most recent gem version.
def check_for_old_dependencies
outdated_gems = list_gems
parsed_gems = parse_outdated_gems outdated_gems
results = check_age parsed_gems
ordered = results.sort_by { |gem| gem[1] }
File.open('results.json', 'w') { |f| f.write JSON.dump(ordered) }
print_results ordered
end
def list_gems
puts "Running 'bundle outdated'\n"
`bundle outdated --parseable --only-explicit`
end
def parse_outdated_gems(raw)
raw.split("\n").reject(&:empty?).map do |line|
gem = line.split(' ')
{ gem_name: gem[0], gem_newest_version: gem[2].gsub(',', '') }
end
end
def print_results(gems)
puts "Outdated gems sorted by date of their last built\n"
gems.each { |gem| puts "#{gem[:gem_name]}: #{gem[:gem_last_built]}"}
end
def check_age(gems)
puts "Getting latest gem versions @ rubygems.org\n"
results = gems.map do |gem|
url = URI.parse("https://rubygems.org/api/v2/rubygems/#{gem[:gem_name]}/versions/#{gem[:gem_newest_version]}.json")
res = Net::HTTP.get_response url
parsed = JSON.parse res.body
{ gem_name: gem[:gem_name], gem_last_built: parsed['built_at'], gem_newest_version: gem[:gem_newest_version] }
end
end
check_for_old_dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment