Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created October 21, 2013 02:25
Show Gist options
  • Save kyanny/7077832 to your computer and use it in GitHub Desktop.
Save kyanny/7077832 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems/command'
require 'uri'
class GitHub
def initialize(gem_name, versions)
@gem_name = gem_name
old_version, new_version = *versions
@old_version = Gem::Version.new(old_version)
@new_version = Gem::Version.new(new_version)
end
def homepage
Gem::Specification.find_by_name(@gem_name).homepage.to_s.sub(/\Ahttps?/, 'https')
end
def diff_url(suffix = '')
"#{homepage}/compare/#{suffix}#{@old_version}...#{suffix}#{@new_version}"
end
def github?
homepage.match(/\Ahttps?:\/\/github\.com\//)
end
end
class Diff
def initialize
@gems = Hash.new { |h, k| h[k] = [] }
end
def push(line)
parse1 line
end
alias_method :<<, :push
def parse1(line)
regexp = /\A
([+-]) # sign
\s*
(\S+) # gem_name
\s*
\(
([\d.]+) # version_number
\)
\s*
\z/x
sign, gem_name, version_number = line.match(regexp).captures
@gems[gem_name] << version_number
rescue NoMethodError
end
def each(&block)
@gems.each do |gem_name, versions|
yield(gem_name, versions) if block_given?
end
end
end
@diff = Diff.new
ARGF.readlines.each do |line|
@diff << line
end
@diff.each do |gem_name, versions|
github = GitHub.new(gem_name, versions)
next unless github.github?
begin
open(github.diff_url)
`open #{github.diff_url}`
rescue
open(github.diff_url('v'))
`open #{github.diff_url('v')}`
end
end
@teeparham
Copy link

Interesting! I just found this. I built something very similar this weekend. I thought you might be interested and maybe even like to contribute:

https://github.com/teeparham/gemdiff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment