Last active
February 8, 2022 16:02
-
-
Save zorbash/7f1fa8e2326b706028b72db91ce047e6 to your computer and use it in GitHub Desktop.
Fetch changelogs of updatable gems
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
require 'bundler' | |
require 'net/http' | |
require 'json' | |
require 'uri' | |
def fetch_gem(gem_name) | |
URI("https://rubygems.org/api/v1/gems/#{gem_name}.json"). | |
then(&Net::HTTP.method(:get)). | |
then(&JSON.method(:parse)) | |
rescue JSON::ParserError | |
{} | |
end | |
def fetch_changelog(gemspec) | |
uri = gemspec.dig('metadata', 'changelog_uri') | |
return unless uri | |
URI(uri.sub('github.com', 'raw.githubusercontent.com').sub('/blob', '')).then(&Net::HTTP.method(:get)) | |
end | |
def changelog_output(current_version, latest_version, changelog) | |
return '' if changelog.nil? | |
changelog.gsub /##? +v?#{current_version}.*/m, '' | |
end | |
Bundler.locked_gems.specs.map do |spec| | |
name = spec.name | |
version = spec.version.to_s | |
gemspec = fetch_gem(name) | |
latest_version = gemspec['version'] | |
if latest_version && version != latest_version | |
changelog = fetch_changelog(gemspec) | |
puts <<~OUT | |
gem: #{name} | |
Current version: #{version} | |
Latest version: #{latest_version} | |
#{changelog_output(version, latest_version, changelog)} | |
OUT | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment