Skip to content

Instantly share code, notes, and snippets.

@dpaluy
Created October 6, 2013 16:04
Show Gist options
  • Select an option

  • Save dpaluy/6855751 to your computer and use it in GitHub Desktop.

Select an option

Save dpaluy/6855751 to your computer and use it in GitHub Desktop.
Get changelogs for all gems included in a Rails project
#!/usr/bin/env ruby
class GemDetails
attr_accessor :name, :version, :changelog_file
def initialize(name, version)
@name, @version = name, version
end
def self.from_str(str)
match = str.match(/(\S+) \((.*)\)/)
result = self.new(match[1], Gem::Version.new(match[2]))
result.changelog_file = changelog_for_gem(result.name)
puts "process gem #{result.name}"
result
end
end
def changelog_for_gem(gem)
changelogs = `bundle exec gem contents #{gem}`.lines.grep(/history|changelog/i)
if changelogs.empty?
puts "No changelog found for gem #{gem}"
return nil
end
changelogs.first.chomp
end
def bundler_gems
gem_list = `bundle list`.lines.drop(1).map do |line|
line.gsub(/\s*\* /, '')
end
gem_list.map { |gem_str| GemDetails.from_str(gem_str) }
end
def bundler_update
system("bundle update")
end
def bundler_install
system("bundle install")
end
def updated_gems(initial_gems, new_gems)
result = []
initial_gems.each do |gem|
updated_gem = new_gems.find { |new_gem| gem.name == new_gem.name && gem.version < new_gem.version }
result << [gem, updated_gem] if updated_gem
end
result
end
def changelog_diff
initial_gems = bundler_gems
puts "Updating bundle"
system('bundle update')
new_gems = bundler_gems
File.open('bundler_gem_diff.txt', 'w') do |f|
updated_gems(initial_gems, new_gems).each do |gem_pair|
f.puts "###### #{gem_pair[0].name} #{gem_pair[0].version} -> #{gem_pair[1].version} ######"
if gem_pair[0].changelog_file && gem_pair[1].changelog_file
puts "diff #{gem_pair[0].changelog_file} #{gem_pair[1].changelog_file}"
f.puts `diff #{gem_pair[0].changelog_file} #{gem_pair[1].changelog_file}`
else
f.puts "Missing changelogs"
end
end
end
system('git checkout Gemfile.lock')
system('bundle install')
nil
end
changelog_diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment