-
-
Save fuzzmonkey/4943845 to your computer and use it in GitHub Desktop.
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
## Gem Upgrade check | |
# | |
# Check your github repos for out of date gems | |
# | |
# usage: $ USERNAME=yourusername PASSWORD=yourpassword GEM=gemname VERSIONS=1.1,1.2,1.3 ruby railscheck.rb | |
# or | |
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname GEM=gemname VERSIONS=1.1,1.2,1.3 ruby railscheck.rb | |
# | |
# n.b requires the octokit gem | |
require 'rubygems' | |
require 'octokit' | |
USERNAME = ENV['USERNAME'] | |
PASSWORD = ENV['PASSWORD'] | |
GEM_NAME = ENV['GEM'] | |
VERSIONS = ENV['VERSIONS'].split(',') # safe versions, comma seperated | |
ORG = ENV['ORG'] | |
REGEX = / #{GEM_NAME} \((\d.+)\)/ | |
client = Octokit::Client.new(:login => USERNAME, :password => PASSWORD, :auto_traversal => true) | |
if !ORG.nil? | |
repos = client.org_repos(ORG) | |
else | |
repos = client.repos | |
end | |
need_updating = [] | |
up_to_date = [] | |
repos.each do |repo| | |
puts '' | |
puts repo.full_name | |
begin | |
gemlock = client.contents(repo.full_name, :path => 'Gemfile.lock') | |
gemlock_content = Base64.decode64(gemlock.content) | |
match = gemlock_content.match(REGEX) | |
if match | |
puts " #{match[1]}" | |
# TODO should major & minor versions | |
# e.g rack | |
update = VERSIONS.include?(match[1]) | |
if update | |
up_to_date << [repo.full_name, match[1]] | |
else | |
need_updating << [repo.full_name, match[1]] | |
end | |
else | |
puts " #{GEM} not found in Gemfile" | |
end | |
rescue | |
puts " No Gemfile.lock" | |
end | |
end | |
unless need_updating.length.zero? | |
puts '' | |
puts '*'*20 | |
puts '' | |
puts "Repos that need updating:" | |
puts '' | |
need_updating.sort! | |
need_updating.each do |r| | |
puts " #{r[0]} - #{r[1]}" | |
end | |
puts '' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment