-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require 'travis/cli' | ||
require 'json' | ||
|
||
module Travis | ||
module CLI | ||
class Setup < RepoCommand | ||
on('-f', '--force', 'override config section if it already exists') | ||
|
||
def run(service) | ||
error "unknown service #{service}" unless respond_to? "setup_#{service}" | ||
public_send "setup_#{service}" | ||
end | ||
|
||
def setup_heroku | ||
configure 'deploy', 'provider' => 'heroku' do |config| | ||
config['api_key'] = `heroku auth:token 2>/dev/null`.strip | ||
config['api_key'] = ask("Heroku API token: ") { |q| q.echo = "*" }.to_s if config['api_key'].empty? | ||
config['app'] = `heroku apps:info 2>/dev/null`.scan(/^=== (.+)$/).flatten.first | ||
config['app'] = ask("Heroku application name: ") { |q| q.default = repository.name }.to_s if config['app'].nil? | ||
config['on'] = { 'repo' => repository.slug } if agree("Deploy only from #{repository.slug}? ") { |q| q.default = 'yes' } | ||
encrypt(config, 'api_key') if agree("Encrypt API key? ") { |q| q.default = 'yes' } | ||
end | ||
end | ||
|
||
def setup_openshift | ||
configure 'deploy', 'provider' => 'openshift' do |config| | ||
config['user'] = ask("OpenShift user: ").to_s | ||
config['password'] = ask("OpenShift password: ") { |q| q.echo = "*" }.to_s | ||
config['app'] = ask("OpenShift application name: ") { |q| q.default = repository.name }.to_s | ||
config['domain'] = ask("OpenShift domain: ").to_s | ||
config['on'] = { 'repo' => repository.slug } if agree("Deploy only from #{repository.slug}? ") { |q| q.default = 'yes' } | ||
encrypt(config, 'password') if agree("Encrypt password? ") { |q| q.default = 'yes' } | ||
end | ||
end | ||
|
||
def setup_nodejitsu | ||
configure 'deploy', 'provider' => 'nodejitsu' do |config| | ||
jitsu_file = File.expand_path('.jitsuconf', ENV['HOME']) | ||
|
||
if File.exist? jitsu_file | ||
jitsu_conf = JSON.parse(File.read(jitsu_file)) | ||
config['user'] = jitsu_conf['username'] | ||
config['api_key'] = jitsu_conf['apiToken'] | ||
end | ||
|
||
config['user'] ||= ask("Nodejitsu user: ").to_s | ||
config['api_key'] ||= ask("Nodejitsu API token: ") { |q| q.echo = "*" }.to_s | ||
config['on'] = { 'repo' => repository.slug } if agree("Deploy only from #{repository.slug}? ") { |q| q.default = 'yes' } | ||
encrypt(config, 'api_key') if agree("Encrypt API key? ") { |q| q.default = 'yes' } | ||
end | ||
end | ||
|
||
def setup_sauce_connect | ||
travis_config['addons'] ||= {} | ||
configure 'sauce_connect', {}, travis_config['addons'] do |config| | ||
config['username'] = ask("Sauce Labs user: ").to_s | ||
config['access_key'] = ask("Sauce Labs access key: ") { |q| q.echo = "*" }.to_s | ||
encrypt(config, 'access_key') if agree("Encrypt access key? ") { |q| q.default = 'yes' } | ||
end | ||
end | ||
|
||
alias setup_sauce_lab setup_sauce_connect | ||
alias setup_sauce setup_sauce_connect | ||
|
||
private | ||
|
||
def encrypt(config, key) | ||
encrypted = repository.encrypt(config.fetch(key)) | ||
config[key] = { 'secure' => encrypted } | ||
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? | ||
result = yield(config[key] = value) | ||
save_travis_config | ||
result | ||
end | ||
end | ||
end | ||
end |
This file contains 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