Created
October 8, 2012 10:09
-
-
Save bradleypriest/3851798 to your computer and use it in GitHub Desktop.
Open all of your updated gem's changes at once
This file contains hidden or 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
| #!/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