Skip to content

Instantly share code, notes, and snippets.

@bradleypriest
Created October 8, 2012 10:09
Show Gist options
  • Save bradleypriest/3851798 to your computer and use it in GitHub Desktop.
Save bradleypriest/3851798 to your computer and use it in GitHub Desktop.
Open all of your updated gem's changes at once
#!/usr/bin/env ruby
VERSION_REGEX = /\((\d.+)\)/
require 'net/http'
require 'json'
lines = `git diff Gemfile.lock`.split("\n")
# Line is a diffed line
lines.select!{ |line| ['+ ', '- '].include?(line.strip[0..1])}
# Line has a version
lines.select!{ |line| line.match(VERSION_REGEX) }
added, removed = {}, {}
lines.each do |line|
name, version = line[1..-1].strip.split
version = version.match(VERSION_REGEX).captures.first
if line[0] == "+"
added[name] = version
else
removed[name] = version
end
end
added.each do |name, version|
json = JSON.parse Net::HTTP.get_response('rubygems.org', "/api/v1/gems/#{name}.json").body
uri = nil
%w{ source_code_uri homepage_uri }.each do |key|
next if uri
uri = json[key] && json[key].match(/github\.com/) && json[key]
end
if uri
uri = "#{uri}/compare/v#{removed[name]}...v#{version}" if removed.has_key?(name)
`open #{uri}`
else
puts "Can't find github URL for gem: #{name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment