Skip to content

Instantly share code, notes, and snippets.

@gshaw
Created December 14, 2018 21:57
Show Gist options
  • Save gshaw/f622d4d5c9734267e8992ade117ae1d1 to your computer and use it in GitHub Desktop.
Save gshaw/f622d4d5c9734267e8992ade117ae1d1 to your computer and use it in GitHub Desktop.
#!/env/bin ruby
require "fileutils"
def process(dir)
puts "Analyzing #{dir}"
FileUtils.cd(dir)
puts "Finding outdated gems"
output = `bundle outdated --strict --only-explicit --parseable`
output.each_line do |line|
next if line.blank?
gem_name, newest_version, installed_version = parse_outdated_line(line)
next if gem_name.nil?
puts "Updating gem #{gem_name} to #{newest_version} from #{installed_version}"
upgrade_gem(gem_name)
end
end
def upgrade_gem(gem_name)
`git checkout master`
`git checkout -b update-gem-#{gem_name}`
`bundle update #{gem_name}`
`git add Gemfile.lock`
`git commit -m 'Update gem #{gem_name}'`
`git push`
`hub pull-request -m 'Update gem #{gem_name}'`
end
def parse_outdated_line(line)
/(.+) \(newest (.+), installed (.+)\)/.match(line)&.captures
end
process("/Users/gshaw/Sites/chitchats")
@jbuyco
Copy link

jbuyco commented Dec 14, 2018

Would there be value in adding the gem version in the PR desc / commit message?

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