lib/travis/cli/command.rb in travis-1.2.8 vs lib/travis/cli/command.rb in travis-1.3.0
- old
+ new
@@ -1,11 +1,13 @@
require 'travis/cli'
require 'travis/tools/formatter'
+require 'travis/version'
require 'highline'
require 'forwardable'
require 'yaml'
+require 'timeout'
module Travis
module CLI
class Command
extend Parser
@@ -31,10 +33,11 @@
HighLine.use_color = v unless CLI.windows?
c.force_interactive = v
end
on('-E', '--[no-]explode', "don't rescue exceptions")
+ on('--skip-version-check', "don't check if travis client is up to date")
def self.command_name
name[/[^:]*$/].downcase
end
@@ -93,12 +96,33 @@
end
def setup
end
+ def check_version
+ return if skip_version_check?
+ return if Time.now.to_i - config['last_version_check'].to_i < 3600
+ version = Travis::VERSION
+
+ Timeout.timeout 1.0 do
+ response = Faraday.get('https://rubygems.org/api/v1/gems/travis.json', {}, 'If-None-Match' => config['etag'].to_s)
+ config['etag'] = response.headers['etag']
+ version = JSON.parse(response.body)['version'] if response.status == 200
+ end
+
+ if Travis::VERSION >= version
+ config['last_version_check'] = Time.now.to_i
+ else
+ error "Outdated CLI version (#{Travis::VERSION}, current is #{version}), " \
+ "run `gem install travis -v #{version}` or use --skip-version-check."
+ end
+ rescue Timeout::Error, Faraday::Error::ClientError
+ end
+
def execute
check_arity(method(:run), *arguments)
load_config
+ check_version
setup
run(*arguments)
store_config
rescue StandardError => e
raise(e) if explode?