lib/travis/cli/setup/service.rb in travis-1.11.1 vs lib/travis/cli/setup/service.rb in travis-1.12.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'travis/cli/setup' module Travis module CLI class Setup @@ -7,11 +9,11 @@ def self.normalized_name(string) string.to_s.downcase.gsub(/[^a-z\d]/, '') end def self.description(description = nil) - @description ||= "" + @description ||= '' @description = description if description @description end def self.service_name(service_name = nil) @@ -34,42 +36,51 @@ @command.send(*args, &block) end private - def on(question, config, condition) - return unless agree(question) { |q| q.default = 'yes' } - config['on'] ||= {} - config['on'].merge! condition - end + def on(question, config, condition) + return unless agree(question) { |q| q.default = 'yes' } - def encrypt(config, key) - encrypted = repository.encrypt(config.fetch(key)) - config[key] = { 'secure' => encrypted } - end + config['on'] ||= {} + config['on'].merge! condition + end - def configure(key, value = {}, config = travis_config) - error "#{key} section already exists in .travis.yml, run with --force to override" if config.include? key and not force? - yield(config[key] = value) - end + def encrypt(config, key) + encrypted = repository.encrypt(config.fetch(key)) + config[key] = { 'secure' => encrypted } + end - def branch - @branch ||= `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.chomp + def configure(key, value = {}, config = travis_config) + if config.include?(key) && !force? + error "#{key} section already exists in .travis.yml, run with --force to override" end + yield(config[key] = value) + end - def deploy(provider, verb = "deploy") - configure('deploy', 'provider' => provider) do |config| - yield config + def branch + @branch ||= `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.chomp + end - on("#{verb.capitalize} only from #{repository.slug}? ", config, 'repo' => repository.slug) - on("#{verb.capitalize} from #{branch} branch? ", config, 'branch' => branch) if branch != 'master' and branch != 'HEAD' + def deploy(provider, verb = 'deploy') + configure('deploy', 'provider' => provider) do |config| + yield config - config['skip_cleanup'] = 'true' if not ( config.has_key?('skip_cleanup') or config.fetch('edge', 'false') != 'false' ) - - encrypt(config, 'password') if config['password'] and agree("Encrypt Password? ") { |q| q.default = 'yes' } - encrypt(config, 'api_key') if config['api_key'] and agree("Encrypt API key? ") { |q| q.default = 'yes' } + on("#{verb.capitalize} only from #{repository.slug}? ", config, 'repo' => repository.slug) + if (branch != 'master') && (branch != 'HEAD') + on("#{verb.capitalize} from #{branch} branch? ", config, + 'branch' => branch) end + + config['skip_cleanup'] = 'true' unless config.key?('skip_cleanup') || (config.fetch('edge', + 'false') != 'false') + + encrypt(config, 'password') if config['password'] && agree('Encrypt Password? ') do |q| + q.default = 'yes' + end + encrypt(config, 'api_key') if config['api_key'] && agree('Encrypt API key? ') { |q| q.default = 'yes' } end + end end end end end