travis-async-listener 1.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +2486 -0
  4. data/Rakefile +63 -0
  5. data/assets/cacert.pem +69 -0
  6. data/assets/init/c.yml +4 -0
  7. data/assets/init/clojure.yml +1 -0
  8. data/assets/init/cpp.yml +4 -0
  9. data/assets/init/erlang.yml +3 -0
  10. data/assets/init/go.yml +4 -0
  11. data/assets/init/groovy.yml +1 -0
  12. data/assets/init/haskell.yml +1 -0
  13. data/assets/init/java.yml +4 -0
  14. data/assets/init/node_js.yml +4 -0
  15. data/assets/init/objective-c.yml +1 -0
  16. data/assets/init/perl.yml +4 -0
  17. data/assets/init/php.yml +4 -0
  18. data/assets/init/python.yml +5 -0
  19. data/assets/init/ruby.yml +6 -0
  20. data/assets/init/scala.yml +4 -0
  21. data/assets/notifications/Travis CI.app/Contents/Info.plist +52 -0
  22. data/assets/notifications/Travis CI.app/Contents/MacOS/Travis CI +0 -0
  23. data/assets/notifications/Travis CI.app/Contents/PkgInfo +1 -0
  24. data/assets/notifications/Travis CI.app/Contents/Resources/Travis CI.icns +0 -0
  25. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
  26. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
  27. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
  28. data/assets/notifications/Travis CI.app/Contents/_CodeSignature/CodeResources +173 -0
  29. data/assets/notifications/Travis CI.app/Contents/embedded.provisionprofile +0 -0
  30. data/assets/notifications/icon.png +0 -0
  31. data/assets/travis.sh +163 -0
  32. data/assets/travis.sh.erb +64 -0
  33. data/bin/travis +18 -0
  34. data/examples/org_overview.rb +3 -0
  35. data/examples/pro_auth.rb +23 -0
  36. data/examples/stream.rb +6 -0
  37. data/lib/travis.rb +8 -0
  38. data/lib/travis/auto_login.rb +3 -0
  39. data/lib/travis/cli.rb +126 -0
  40. data/lib/travis/cli/accounts.rb +31 -0
  41. data/lib/travis/cli/api_command.rb +180 -0
  42. data/lib/travis/cli/branches.rb +25 -0
  43. data/lib/travis/cli/cache.rb +76 -0
  44. data/lib/travis/cli/cancel.rb +18 -0
  45. data/lib/travis/cli/command.rb +422 -0
  46. data/lib/travis/cli/console.rb +31 -0
  47. data/lib/travis/cli/disable.rb +15 -0
  48. data/lib/travis/cli/enable.rb +31 -0
  49. data/lib/travis/cli/encrypt.rb +108 -0
  50. data/lib/travis/cli/encrypt_file.rb +140 -0
  51. data/lib/travis/cli/endpoint.rb +35 -0
  52. data/lib/travis/cli/env.rb +66 -0
  53. data/lib/travis/cli/help.rb +23 -0
  54. data/lib/travis/cli/history.rb +49 -0
  55. data/lib/travis/cli/init.rb +82 -0
  56. data/lib/travis/cli/lint.rb +49 -0
  57. data/lib/travis/cli/login.rb +76 -0
  58. data/lib/travis/cli/logout.rb +14 -0
  59. data/lib/travis/cli/logs.rb +65 -0
  60. data/lib/travis/cli/monitor.rb +110 -0
  61. data/lib/travis/cli/open.rb +39 -0
  62. data/lib/travis/cli/parser.rb +43 -0
  63. data/lib/travis/cli/pubkey.rb +30 -0
  64. data/lib/travis/cli/raw.rb +20 -0
  65. data/lib/travis/cli/repo_command.rb +154 -0
  66. data/lib/travis/cli/report.rb +101 -0
  67. data/lib/travis/cli/repos.rb +53 -0
  68. data/lib/travis/cli/requests.rb +47 -0
  69. data/lib/travis/cli/restart.rb +18 -0
  70. data/lib/travis/cli/settings.rb +77 -0
  71. data/lib/travis/cli/setup.rb +66 -0
  72. data/lib/travis/cli/setup/anynines.rb +21 -0
  73. data/lib/travis/cli/setup/appfog.rb +19 -0
  74. data/lib/travis/cli/setup/artifacts.rb +23 -0
  75. data/lib/travis/cli/setup/biicode.rb +19 -0
  76. data/lib/travis/cli/setup/cloud_66.rb +20 -0
  77. data/lib/travis/cli/setup/cloud_control.rb +21 -0
  78. data/lib/travis/cli/setup/cloud_files.rb +20 -0
  79. data/lib/travis/cli/setup/cloud_foundry.rb +23 -0
  80. data/lib/travis/cli/setup/code_deploy.rb +55 -0
  81. data/lib/travis/cli/setup/deis.rb +20 -0
  82. data/lib/travis/cli/setup/divshot.rb +18 -0
  83. data/lib/travis/cli/setup/elastic_beanstalk.rb +23 -0
  84. data/lib/travis/cli/setup/engine_yard.rb +24 -0
  85. data/lib/travis/cli/setup/gcs.rb +22 -0
  86. data/lib/travis/cli/setup/hackage.rb +18 -0
  87. data/lib/travis/cli/setup/heroku.rb +20 -0
  88. data/lib/travis/cli/setup/modulus.rb +18 -0
  89. data/lib/travis/cli/setup/ninefold.rb +20 -0
  90. data/lib/travis/cli/setup/nodejitsu.rb +27 -0
  91. data/lib/travis/cli/setup/npm.rb +20 -0
  92. data/lib/travis/cli/setup/open_shift.rb +20 -0
  93. data/lib/travis/cli/setup/opsworks.rb +22 -0
  94. data/lib/travis/cli/setup/pypi.rb +22 -0
  95. data/lib/travis/cli/setup/releases.rb +35 -0
  96. data/lib/travis/cli/setup/ruby_gems.rb +25 -0
  97. data/lib/travis/cli/setup/s3.rb +25 -0
  98. data/lib/travis/cli/setup/sauce_connect.rb +21 -0
  99. data/lib/travis/cli/setup/service.rb +73 -0
  100. data/lib/travis/cli/show.rb +69 -0
  101. data/lib/travis/cli/sshkey.rb +118 -0
  102. data/lib/travis/cli/status.rb +19 -0
  103. data/lib/travis/cli/sync.rb +30 -0
  104. data/lib/travis/cli/token.rb +14 -0
  105. data/lib/travis/cli/version.rb +17 -0
  106. data/lib/travis/cli/whatsup.rb +30 -0
  107. data/lib/travis/cli/whoami.rb +15 -0
  108. data/lib/travis/client.rb +39 -0
  109. data/lib/travis/client/account.rb +56 -0
  110. data/lib/travis/client/annotation.rb +21 -0
  111. data/lib/travis/client/artifact.rb +88 -0
  112. data/lib/travis/client/auto_login.rb +45 -0
  113. data/lib/travis/client/broadcast.rb +14 -0
  114. data/lib/travis/client/build.rb +47 -0
  115. data/lib/travis/client/cache.rb +25 -0
  116. data/lib/travis/client/commit.rb +28 -0
  117. data/lib/travis/client/entity.rb +238 -0
  118. data/lib/travis/client/env_var.rb +102 -0
  119. data/lib/travis/client/error.rb +38 -0
  120. data/lib/travis/client/has_uuid.rb +13 -0
  121. data/lib/travis/client/job.rb +61 -0
  122. data/lib/travis/client/lint_result.rb +25 -0
  123. data/lib/travis/client/listener.rb +184 -0
  124. data/lib/travis/client/methods.rb +104 -0
  125. data/lib/travis/client/namespace.rb +85 -0
  126. data/lib/travis/client/not_loadable.rb +13 -0
  127. data/lib/travis/client/repository.rb +224 -0
  128. data/lib/travis/client/request.rb +36 -0
  129. data/lib/travis/client/restartable.rb +23 -0
  130. data/lib/travis/client/session.rb +339 -0
  131. data/lib/travis/client/settings.rb +25 -0
  132. data/lib/travis/client/singleton_setting.rb +36 -0
  133. data/lib/travis/client/ssh_key.rb +11 -0
  134. data/lib/travis/client/states.rb +98 -0
  135. data/lib/travis/client/user.rb +67 -0
  136. data/lib/travis/client/weak_entity.rb +26 -0
  137. data/lib/travis/pro.rb +5 -0
  138. data/lib/travis/pro/auto_login.rb +3 -0
  139. data/lib/travis/tools/assets.rb +21 -0
  140. data/lib/travis/tools/completion.rb +54 -0
  141. data/lib/travis/tools/formatter.rb +50 -0
  142. data/lib/travis/tools/github.rb +279 -0
  143. data/lib/travis/tools/notification.rb +69 -0
  144. data/lib/travis/tools/safe_string.rb +22 -0
  145. data/lib/travis/tools/ssl_key.rb +48 -0
  146. data/lib/travis/tools/system.rb +88 -0
  147. data/lib/travis/version.rb +3 -0
  148. data/spec/cli/cancel_spec.rb +15 -0
  149. data/spec/cli/encrypt_spec.rb +43 -0
  150. data/spec/cli/endpoint_spec.rb +34 -0
  151. data/spec/cli/help_spec.rb +33 -0
  152. data/spec/cli/history_spec.rb +38 -0
  153. data/spec/cli/init_spec.rb +226 -0
  154. data/spec/cli/login_spec.rb +13 -0
  155. data/spec/cli/logs_spec.rb +8 -0
  156. data/spec/cli/open_spec.rb +33 -0
  157. data/spec/cli/repo_command_spec.rb +25 -0
  158. data/spec/cli/restart_spec.rb +15 -0
  159. data/spec/cli/setup_spec.rb +5 -0
  160. data/spec/cli/show_spec.rb +9 -0
  161. data/spec/cli/status_spec.rb +28 -0
  162. data/spec/cli/token_spec.rb +22 -0
  163. data/spec/cli/version_spec.rb +18 -0
  164. data/spec/cli/whoami_spec.rb +34 -0
  165. data/spec/client/account_spec.rb +32 -0
  166. data/spec/client/annotation_spec.rb +14 -0
  167. data/spec/client/broadcast_spec.rb +10 -0
  168. data/spec/client/build_spec.rb +31 -0
  169. data/spec/client/commit_spec.rb +22 -0
  170. data/spec/client/job_spec.rb +30 -0
  171. data/spec/client/methods_spec.rb +15 -0
  172. data/spec/client/namespace_spec.rb +19 -0
  173. data/spec/client/repository_spec.rb +39 -0
  174. data/spec/client/session_spec.rb +165 -0
  175. data/spec/client/user_spec.rb +16 -0
  176. data/spec/client_spec.rb +17 -0
  177. data/spec/pro_spec.rb +10 -0
  178. data/spec/spec_helper.rb +29 -0
  179. data/spec/support/fake_api.rb +738 -0
  180. data/spec/support/fake_github.rb +24 -0
  181. data/spec/support/helpers.rb +45 -0
  182. data/spec/travis_spec.rb +10 -0
  183. data/travis.gemspec +323 -0
  184. metadata +489 -0
@@ -0,0 +1,31 @@
1
+ require 'travis/cli'
2
+
3
+ module Travis
4
+ module CLI
5
+ class Console < ApiCommand
6
+ description "interactive shell"
7
+ on '-x', '--eval LINE', 'run line of ruby' do |c, line|
8
+ c.instance_eval(line)
9
+ exit
10
+ end
11
+
12
+ def run
13
+ return unless pry_installed?
14
+
15
+ Object.send(:include, Client::Namespace.new(session))
16
+ hooks = defined?(Pry::Hooks) ? Pry::Hooks.new : {}
17
+ binding.pry(:quiet => true, :prompt => Pry::SIMPLE_PROMPT, :output => $stdout, :hooks => hooks)
18
+ end
19
+
20
+ private
21
+
22
+ def pry_installed?
23
+ require 'pry'
24
+ true
25
+ rescue LoadError
26
+ $stderr.puts 'You need to install pry to use Travis CLI console.'
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'travis/cli'
2
+
3
+ module Travis
4
+ module CLI
5
+ class Disable < RepoCommand
6
+ description "disables a project"
7
+
8
+ def run
9
+ authenticate
10
+ repository.disable
11
+ say "disabled", color("#{slug}: %s :(", :error)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require 'travis/cli'
2
+
3
+ module Travis
4
+ module CLI
5
+ class Enable < RepoCommand
6
+ description "enables a project"
7
+ on('-s', '--skip-sync', "don't trigger a sync if the repo is unknown")
8
+
9
+ def run
10
+ authenticate
11
+ error "not allowed to update service hook for #{color(repository.slug, :bold)}" unless repository.admin?
12
+ repository.enable
13
+ say "enabled", color("#{slug}: %s :)", :success)
14
+ end
15
+
16
+ private
17
+
18
+ def repository
19
+ repo(slug)
20
+ rescue Travis::Client::NotFound
21
+ unless skip_sync?
22
+ say "repository not known to Travis CI (or no access?)"
23
+ say "triggering sync: "
24
+ sync
25
+ say " done"
26
+ end
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,108 @@
1
+ # encoding: utf-8
2
+ require 'travis/cli'
3
+
4
+ module Travis
5
+ module CLI
6
+ class Encrypt < RepoCommand
7
+ description "encrypts values for the .travis.yml"
8
+ attr_accessor :config_key
9
+
10
+ on('-a', '--add [KEY]', 'adds it to .travis.yml under KEY (default: env.global)') do |c, value|
11
+ c.config_key = value || 'env.global'
12
+ end
13
+
14
+ on('-s', '--[no-]split', "treat each line as a separate input")
15
+ on('-p', '--append', "don't override existing values, instead treat as list")
16
+ on('-x', '--override', "override existing value")
17
+
18
+ def run(*args)
19
+ error "cannot combine --override and --append" if append? and override?
20
+ error "--append without --add makes no sense" if append? and not add?
21
+ error "--override without --add makes no sense" if override? and not add?
22
+ self.override |= !config_key.start_with?('env.') if add? and not append?
23
+
24
+ if args.first =~ %r{\w+/\w+} && !args.first.include?("=")
25
+ warn "WARNING: The name of the repository is now passed to the command with the -r option:"
26
+ warn " #{command("encrypt [...] -r #{args.first}")}"
27
+ warn " If you tried to pass the name of the repository as the first argument, you"
28
+ warn " probably won't get the results you wanted.\n"
29
+ end
30
+
31
+ data = args.join(" ")
32
+
33
+ if data.empty?
34
+ say color("Reading from stdin, press Ctrl+D when done", :info) if $stdin.tty?
35
+ data = $stdin.read
36
+ end
37
+
38
+ data = split? ? data.split("\n") : [data.strip]
39
+ encrypted = data.map { |data| repository.encrypt(data) }
40
+
41
+ if config_key
42
+ set_config encrypted.map { |e| { 'secure' => e } }
43
+ save_travis_config
44
+ else
45
+ list = encrypted.map { |data| format(data.inspect, " secure: %s") }
46
+ say(list.join("\n"), template(__FILE__), :none)
47
+ end
48
+ rescue OpenSSL::PKey::RSAError => error
49
+ error "#{error.message.sub(" for key size", "")} - consider using " <<
50
+ color("travis encrypt-file", [:red, :bold]) <<
51
+ color(" or ", :red) <<
52
+ color("travis env set", [:red, :bold])
53
+ end
54
+
55
+ private
56
+
57
+ def add?
58
+ !!config_key
59
+ end
60
+
61
+ def set_config(result)
62
+ parent_config[last_key] = merge_config(result)
63
+ end
64
+
65
+ def merge_config(result)
66
+ case subconfig = (parent_config[last_key] unless override?)
67
+ when nil then result.size == 1 ? result.first : result
68
+ when Array then subconfig + result
69
+ else result.unshift(subconfig)
70
+ end
71
+ end
72
+
73
+ def subconfig
74
+ end
75
+
76
+ def key_chain
77
+ @key_chain ||= config_key.split('.')
78
+ end
79
+
80
+ def last_key
81
+ key_chain.last
82
+ end
83
+
84
+ def parent_config
85
+ @parent_config ||= traverse_config(travis_config, *key_chain[0..-2])
86
+ end
87
+
88
+ def traverse_config(hash, key = nil, *rest)
89
+ return hash unless key
90
+
91
+ hash[key] = case value = hash[key]
92
+ when nil then {}
93
+ when Hash then value
94
+ else { 'matrix' => Array(value) }
95
+ end
96
+
97
+ traverse_config(hash[key], *rest)
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ __END__
104
+ Please add the following to your <[[ color('.travis.yml', :info) ]]> file:
105
+
106
+ %s
107
+
108
+ Pro Tip: You can add it automatically by running with <[[ color('--add', :info) ]]>.
@@ -0,0 +1,140 @@
1
+ # encoding: utf-8
2
+ require 'travis/cli'
3
+ require 'travis/tools/system'
4
+
5
+ require 'securerandom'
6
+ require 'openssl'
7
+ require 'digest'
8
+ require 'shellwords'
9
+
10
+ module Travis
11
+ module CLI
12
+ class EncryptFile < RepoCommand
13
+ attr_accessor :stage
14
+ description 'encrypts a file and adds decryption steps to .travis.yml'
15
+ on '-K', '--key KEY', 'encryption key to be used (randomly generated otherwise)'
16
+ on '--iv IV', 'encryption IV to be used (randomly generated otherwise)'
17
+ on '-d', '--decrypt', 'decrypt the file instead of encrypting it, requires key and iv'
18
+ on '-f', '--force', 'override output file if it exists'
19
+ on '-p', '--print-key', 'print (possibly generated) key and iv'
20
+ on '-w', '--decrypt-to PATH', 'where to write the decrypted file to on the Travis CI VM'
21
+ on '-a', '--add [STAGE]', 'automatically add command to .travis.yml (default stage is before_install)' do |c, stage|
22
+ c.stage = stage || 'before_install'
23
+ end
24
+
25
+ def run(input_path, output_path = nil)
26
+ self.decrypt_to ||= decrypt_to_for(input_path)
27
+ output_path ||= File.basename(output_path_for(input_path))
28
+ self.output = $stdout.tty? ? StringIO.new : $stderr if output_path == '-'
29
+ result = transcode(input_path)
30
+
31
+ if output_path == '-'
32
+ $stdout.puts result
33
+ else
34
+ say "storing result as #{color(output_path, :info)}"
35
+ write_file(output_path, result, force)
36
+ return if decrypt?
37
+
38
+ error "requires --decrypt-to option when reading from stdin" unless decrypt_to?
39
+
40
+ set_env_vars
41
+
42
+ command = decrypt_command(output_path)
43
+ stage ? store_command(command) : print_command(command)
44
+
45
+ notes(input_path, output_path)
46
+ end
47
+ end
48
+
49
+ def setup
50
+ super
51
+ self.key ||= SecureRandom.hex(32) unless decrypt?
52
+ self.iv ||= SecureRandom.hex(16) unless decrypt?
53
+ error "key must be 64 characters long and a valid hex number" unless key =~ /^[a-f0-9]{64}$/
54
+ error "iv must be 32 characters long and a valid hex number" unless iv =~ /^[a-f0-9]{32}$/
55
+ end
56
+
57
+ def print_command(command)
58
+ empty_line
59
+ say command, template(__FILE__)
60
+ end
61
+
62
+ def store_command(command)
63
+ travis_config[stage] = Array(travis_config[stage])
64
+ travis_config[stage].delete(command)
65
+ travis_config[stage].unshift(command)
66
+ save_travis_config
67
+ end
68
+
69
+ def decrypt_command(path)
70
+ "openssl aes-256-cbc -K $#{env_name(:key)} -iv $#{env_name(:iv)} -in #{escape_path(path)} -out #{escape_path(decrypt_to)} -d"
71
+ end
72
+
73
+ def set_env_vars
74
+ say "storing secure env variables for decryption"
75
+ repository.env_vars.upsert env_name(:key), key, :public => false
76
+ repository.env_vars.upsert env_name(:iv), iv, :public => false
77
+ end
78
+
79
+ def env_name(name)
80
+ @env_prefix ||= "encrypted_#{Digest.hexencode(Digest::SHA1.digest(Dir.pwd)[0..5])}"
81
+ "#{@env_prefix}_#{name}"
82
+ end
83
+
84
+ def notes(input_path, output_path)
85
+ say "\nkey: #{color(key, :info)}\niv: #{color(iv, :info)}" if print_key?
86
+ empty_line
87
+ say "Make sure to add #{color(output_path, :info)} to the git repository."
88
+ say "Make sure #{color("not", :underline)} to add #{color(input_path, :info)} to the git repository." if input_path != '-'
89
+ say "Commit all changes to your #{color('.travis.yml', :info)}."
90
+ end
91
+
92
+ def transcode(input_path)
93
+ description = "stdin#{' (waiting for input)' if $stdin.tty?}" if input_path == '-'
94
+ say "#{decrypt ? "de" : "en"}crypting #{color(description || input_path, :info)} for #{color(slug, :info)}"
95
+
96
+ data = input_path == '-' ? $stdin.read : File.binread(input_path)
97
+ aes = OpenSSL::Cipher.new('AES-256-CBC')
98
+ decrypt ? aes.decrypt : aes.encrypt
99
+ aes.key = [key].pack('H*')
100
+ aes.iv = [iv].pack('H*')
101
+
102
+ aes.update(data) + aes.final
103
+ end
104
+
105
+ def decrypt_to_for(input_path)
106
+ return if input_path == '-'
107
+ if input_path.start_with? Dir.home
108
+ input_path.sub(Dir.home, '~')
109
+ else
110
+ input_path
111
+ end
112
+ end
113
+
114
+ def escape_path(path)
115
+ Shellwords.escape(path).sub(/^\\~\//, '~\/')
116
+ end
117
+
118
+ def output_path_for(input_path)
119
+ case input_path
120
+ when '-' then return '-'
121
+ when /^(.+)\.enc$/ then return $1 if decrypt?
122
+ when /^(.+)\.dec$/ then return $1 unless decrypt?
123
+ end
124
+
125
+ if interactive? and input_path =~ /(\.enc|\.dec)$/
126
+ exit 1 unless danger_zone? "File extension of input file is #{color($1, :info)}, are you sure that is correct?"
127
+ end
128
+
129
+ "#{input_path}.#{decrypt ? 'dec' : 'enc'}"
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ __END__
136
+ Please add the following to your build script (<[[ color('before_install', :info) ]]> stage in your <[[ color('.travis.yml', :info) ]]>, for instance):
137
+
138
+ %s
139
+
140
+ Pro Tip: You can add it automatically by running with <[[ color('--add', :info) ]]>.
@@ -0,0 +1,35 @@
1
+ require 'travis/cli'
2
+
3
+ module Travis
4
+ module CLI
5
+ class Endpoint < ApiCommand
6
+ description "displays or changes the API endpoint"
7
+
8
+ skip :authenticate
9
+ on '--drop-default', 'delete stored default endpoint'
10
+ on '--set-default', 'store endpoint as global default'
11
+ on '--github', 'display github endpoint'
12
+
13
+ def run_github
14
+ error "--github cannot be combined with --drop-default" if drop_default?
15
+ error "--github cannot be combined with --set-default" if set_default?
16
+ load_gh
17
+ say github_endpoint.to_s, "GitHub endpoint: %s"
18
+ end
19
+
20
+ def run_travis
21
+ if drop_default? and was = config['default_endpoint']
22
+ config.delete('default_endpoint')
23
+ say was, "default API endpoint dropped (was %s)"
24
+ else
25
+ config['default_endpoint'] = api_endpoint if set_default?
26
+ say api_endpoint, "API endpoint: %s#{" (stored as default)" if set_default?}"
27
+ end
28
+ end
29
+
30
+ def run
31
+ github? ? run_github : run_travis
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,66 @@
1
+ require 'travis/cli'
2
+ require 'shellwords'
3
+
4
+ module Travis
5
+ module CLI
6
+ class Env < RepoCommand
7
+ on('-P', '--[no-]public', 'make new values public')
8
+ on('-p', '--[no-]private', 'make new values private') { |c,v| c.public = !v }
9
+ on('-u', '--[no-]unescape', 'do not escape values')
10
+ on('-f', '--force', 'do not ask for confirmation when clearing out all variables')
11
+
12
+ description "show or modify build environment variables"
13
+ subcommands :list, :set, :unset, :copy, :clear
14
+
15
+ def setup
16
+ super
17
+ authenticate
18
+ error "not allowed to access environment variables for #{color(repository.slug, :bold)}" unless repository.admin?
19
+ end
20
+
21
+ def set(name, value)
22
+ options ||= { :public => public } if public != nil
23
+ say color('[+] ', [:green, :bold]) + "setting environment variable #{color "$#{name}", :info}"
24
+ value = Shellwords.escape(value) unless unescape?
25
+ env_vars.upsert(name, value, options || {})
26
+ end
27
+
28
+ def copy(*names)
29
+ names.each do |name|
30
+ if ENV.include? name
31
+ set(name, ENV[name])
32
+ else
33
+ warn "missing in current environment: #{color "$#{name}", :bold}"
34
+ end
35
+ end
36
+ end
37
+
38
+ def unset(*names)
39
+ remove_vars { |var| names.include? var.name }
40
+ end
41
+
42
+ def clear
43
+ exit if env_vars.empty?
44
+ exit 1 if interactive? and not force? and not danger_zone? "Clear out all env variables for #{color(repository.slug, :bold)}?"
45
+ remove_vars
46
+ end
47
+
48
+ def remove_vars
49
+ env_vars.each do |var|
50
+ next if block_given? and not yield(var)
51
+ say color('[x] ', [:red, :bold]) + "removing environment variable #{color "$#{var.name}", :info}"
52
+ var.delete
53
+ end
54
+ end
55
+
56
+ def list
57
+ say color("# environment variables for #{color repository.slug, :bold}", :info)
58
+ env_vars.each { |v| say "#{v.name}=" << color(v.value || "[secure]", :bold) }
59
+ end
60
+
61
+ def env_vars
62
+ repository.env_vars
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,23 @@
1
+ require 'travis/cli'
2
+
3
+ module Travis
4
+ module CLI
5
+ class Help < Command
6
+ description "helps you out when in dire need of information"
7
+
8
+ def run(command = nil)
9
+ if command
10
+ say CLI.command(command).new.help
11
+ else
12
+ say "Usage: travis COMMAND ...\n\nAvailable commands:\n\n"
13
+ commands.each { |c| say "\t#{color(c.command_name, :command).ljust(22)} #{color(c.description, :info)}" }
14
+ say "\nrun `#$0 help COMMAND` for more infos"
15
+ end
16
+ end
17
+
18
+ def commands
19
+ CLI.commands.sort_by { |c| c.command_name }
20
+ end
21
+ end
22
+ end
23
+ end