travis 1.11.1 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +9 -3
  3. data/Rakefile +22 -20
  4. data/bin/travis +5 -3
  5. data/examples/org_overview.rb +2 -0
  6. data/examples/pro_auth.rb +3 -1
  7. data/examples/stream.rb +5 -3
  8. data/lib/travis/auto_login.rb +2 -0
  9. data/lib/travis/cli/accounts.rb +12 -9
  10. data/lib/travis/cli/api_command.rb +85 -81
  11. data/lib/travis/cli/branches.rb +8 -6
  12. data/lib/travis/cli/cache.rb +48 -44
  13. data/lib/travis/cli/cancel.rb +4 -2
  14. data/lib/travis/cli/command.rb +170 -142
  15. data/lib/travis/cli/console.rb +5 -5
  16. data/lib/travis/cli/disable.rb +4 -2
  17. data/lib/travis/cli/enable.rb +14 -12
  18. data/lib/travis/cli/encrypt.rb +57 -57
  19. data/lib/travis/cli/encrypt_file.rb +29 -18
  20. data/lib/travis/cli/endpoint.rb +9 -7
  21. data/lib/travis/cli/env.rb +13 -8
  22. data/lib/travis/cli/help.rb +10 -8
  23. data/lib/travis/cli/history.rb +19 -15
  24. data/lib/travis/cli/init.rb +27 -24
  25. data/lib/travis/cli/lint.rb +10 -8
  26. data/lib/travis/cli/login.rb +17 -11
  27. data/lib/travis/cli/logout.rb +4 -2
  28. data/lib/travis/cli/logs.rb +28 -19
  29. data/lib/travis/cli/monitor.rb +11 -8
  30. data/lib/travis/cli/open.rb +17 -14
  31. data/lib/travis/cli/parser.rb +2 -0
  32. data/lib/travis/cli/pubkey.rb +13 -11
  33. data/lib/travis/cli/raw.rb +4 -3
  34. data/lib/travis/cli/repo_command.rb +123 -112
  35. data/lib/travis/cli/report.rb +40 -33
  36. data/lib/travis/cli/repos.rb +14 -9
  37. data/lib/travis/cli/requests.rb +13 -12
  38. data/lib/travis/cli/restart.rb +4 -2
  39. data/lib/travis/cli/settings.rb +41 -35
  40. data/lib/travis/cli/setup/anynines.rb +7 -6
  41. data/lib/travis/cli/setup/appfog.rb +6 -4
  42. data/lib/travis/cli/setup/artifacts.rb +7 -5
  43. data/lib/travis/cli/setup/biicode.rb +6 -4
  44. data/lib/travis/cli/setup/cloud_66.rb +6 -4
  45. data/lib/travis/cli/setup/cloud_control.rb +8 -6
  46. data/lib/travis/cli/setup/cloud_files.rb +7 -5
  47. data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
  48. data/lib/travis/cli/setup/code_deploy.rb +33 -29
  49. data/lib/travis/cli/setup/deis.rb +8 -6
  50. data/lib/travis/cli/setup/divshot.rb +20 -18
  51. data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
  52. data/lib/travis/cli/setup/engine_yard.rb +9 -7
  53. data/lib/travis/cli/setup/gcs.rb +9 -7
  54. data/lib/travis/cli/setup/hackage.rb +6 -4
  55. data/lib/travis/cli/setup/heroku.rb +10 -4
  56. data/lib/travis/cli/setup/modulus.rb +5 -3
  57. data/lib/travis/cli/setup/ninefold.rb +7 -5
  58. data/lib/travis/cli/setup/nodejitsu.rb +6 -4
  59. data/lib/travis/cli/setup/npm.rb +6 -4
  60. data/lib/travis/cli/setup/open_shift.rb +8 -6
  61. data/lib/travis/cli/setup/opsworks.rb +24 -22
  62. data/lib/travis/cli/setup/pypi.rb +7 -5
  63. data/lib/travis/cli/setup/releases.rb +6 -6
  64. data/lib/travis/cli/setup/ruby_gems.rb +7 -5
  65. data/lib/travis/cli/setup/s3.rb +12 -8
  66. data/lib/travis/cli/setup/sauce_connect.rb +7 -5
  67. data/lib/travis/cli/setup/service.rb +36 -25
  68. data/lib/travis/cli/setup.rb +7 -3
  69. data/lib/travis/cli/show.rb +10 -8
  70. data/lib/travis/cli/sshkey.rb +31 -27
  71. data/lib/travis/cli/status.rb +5 -3
  72. data/lib/travis/cli/sync.rb +9 -7
  73. data/lib/travis/cli/token.rb +4 -2
  74. data/lib/travis/cli/version.rb +4 -3
  75. data/lib/travis/cli/whatsup.rb +10 -8
  76. data/lib/travis/cli/whoami.rb +2 -2
  77. data/lib/travis/cli.rb +39 -36
  78. data/lib/travis/client/account.rb +8 -6
  79. data/lib/travis/client/artifact.rb +16 -12
  80. data/lib/travis/client/auto_login.rb +7 -4
  81. data/lib/travis/client/broadcast.rb +2 -0
  82. data/lib/travis/client/build.rb +7 -3
  83. data/lib/travis/client/cache.rb +4 -2
  84. data/lib/travis/client/commit.rb +5 -2
  85. data/lib/travis/client/entity.rb +50 -46
  86. data/lib/travis/client/env_var.rb +13 -8
  87. data/lib/travis/client/error.rb +5 -3
  88. data/lib/travis/client/has_uuid.rb +3 -1
  89. data/lib/travis/client/job.rb +8 -3
  90. data/lib/travis/client/lint_result.rb +2 -0
  91. data/lib/travis/client/listener.rb +70 -55
  92. data/lib/travis/client/methods.rb +10 -5
  93. data/lib/travis/client/namespace.rb +20 -16
  94. data/lib/travis/client/not_loadable.rb +3 -1
  95. data/lib/travis/client/repository.rb +34 -22
  96. data/lib/travis/client/request.rb +5 -2
  97. data/lib/travis/client/restartable.rb +2 -0
  98. data/lib/travis/client/session.rb +118 -88
  99. data/lib/travis/client/settings.rb +8 -3
  100. data/lib/travis/client/singleton_setting.rb +2 -0
  101. data/lib/travis/client/ssh_key.rb +2 -0
  102. data/lib/travis/client/states.rb +8 -6
  103. data/lib/travis/client/user.rb +2 -0
  104. data/lib/travis/client/weak_entity.rb +6 -3
  105. data/lib/travis/client.rb +4 -1
  106. data/lib/travis/pro/auto_login.rb +2 -0
  107. data/lib/travis/pro.rb +2 -0
  108. data/lib/travis/tools/assets.rb +6 -3
  109. data/lib/travis/tools/completion.rb +10 -6
  110. data/lib/travis/tools/formatter.rb +20 -14
  111. data/lib/travis/tools/github.rb +59 -49
  112. data/lib/travis/tools/notification.rb +18 -13
  113. data/lib/travis/tools/safe_string.rb +4 -1
  114. data/lib/travis/tools/ssl_key.rb +5 -2
  115. data/lib/travis/tools/system.rb +11 -6
  116. data/lib/travis/version.rb +3 -1
  117. data/lib/travis.rb +3 -1
  118. data/spec/cli/api_command_spec.rb +11 -8
  119. data/spec/cli/cancel_spec.rb +2 -4
  120. data/spec/cli/encrypt_file_spec.rb +9 -7
  121. data/spec/cli/encrypt_spec.rb +19 -17
  122. data/spec/cli/endpoint_spec.rb +12 -10
  123. data/spec/cli/help_spec.rb +14 -12
  124. data/spec/cli/history_spec.rb +2 -0
  125. data/spec/cli/init_spec.rb +35 -33
  126. data/spec/cli/logs_spec.rb +2 -0
  127. data/spec/cli/open_spec.rb +6 -4
  128. data/spec/cli/repo_command_spec.rb +8 -4
  129. data/spec/cli/restart_spec.rb +2 -4
  130. data/spec/cli/setup/service_spec.rb +17 -18
  131. data/spec/cli/setup_spec.rb +2 -4
  132. data/spec/cli/show_spec.rb +4 -2
  133. data/spec/cli/status_spec.rb +7 -5
  134. data/spec/cli/token_spec.rb +7 -5
  135. data/spec/cli/version_spec.rb +2 -0
  136. data/spec/cli/whoami_spec.rb +9 -7
  137. data/spec/client/account_spec.rb +28 -20
  138. data/spec/client/auto_login_spec.rb +12 -9
  139. data/spec/client/broadcast_spec.rb +5 -3
  140. data/spec/client/build_spec.rb +28 -24
  141. data/spec/client/commit_spec.rb +17 -14
  142. data/spec/client/job_spec.rb +27 -23
  143. data/spec/client/methods_spec.rb +8 -4
  144. data/spec/client/namespace_spec.rb +8 -4
  145. data/spec/client/repository_spec.rb +33 -30
  146. data/spec/client/session_spec.rb +71 -67
  147. data/spec/client/user_spec.rb +13 -10
  148. data/spec/client_spec.rb +6 -4
  149. data/spec/pro_spec.rb +5 -3
  150. data/spec/spec_helper.rb +3 -1
  151. data/spec/support/fake_api.rb +662 -662
  152. data/spec/support/fake_github.rb +6 -3
  153. data/spec/support/helpers.rb +13 -8
  154. data/spec/travis_spec.rb +5 -3
  155. data/travis.gemspec +400 -399
  156. metadata +30 -50
@@ -15,21 +15,23 @@ module Travis
15
15
  class Command
16
16
  MINUTE = 60
17
17
  HOUR = 3600
18
- DAY = 86400
19
- WEEK = 604800
18
+ DAY = 86_400
19
+ WEEK = 604_800
20
20
 
21
21
  include Tools::Assets
22
- extend Parser, Forwardable, Tools::Assets
22
+ extend Tools::Assets
23
+ extend Forwardable
24
+ extend Parser
23
25
  def_delegators :terminal, :agree, :ask, :choose
24
26
 
25
27
  HighLine.use_color = Tools::System.unix? && $stdout.tty?
26
28
  HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
27
- cs[:command] = [ :bold ]
28
- cs[:error] = [ :red ]
29
- cs[:important] = [ :bold, :underline ]
30
- cs[:success] = [ :green ]
31
- cs[:info] = [ :yellow ]
32
- cs[:debug] = [ :magenta ]
29
+ cs[:command] = [:bold]
30
+ cs[:error] = [:red]
31
+ cs[:important] = %i[bold underline]
32
+ cs[:success] = [:green]
33
+ cs[:info] = [:yellow]
34
+ cs[:debug] = [:magenta]
33
35
  end
34
36
 
35
37
  on('-h', '--help', 'Display help') do |c, _|
@@ -37,7 +39,7 @@ module Travis
37
39
  exit
38
40
  end
39
41
 
40
- on('-i', '--[no-]interactive', "be interactive and colorful") do |c, v|
42
+ on('-i', '--[no-]interactive', 'be interactive and colorful') do |c, v|
41
43
  HighLine.use_color = v if Tools::System.unix?
42
44
  c.force_interactive = v
43
45
  end
@@ -65,11 +67,12 @@ module Travis
65
67
 
66
68
  def self.description(description = nil)
67
69
  @description = description if description
68
- @description ||= ""
70
+ @description ||= ''
69
71
  end
70
72
 
71
73
  def self.subcommands(*list)
72
74
  return @subcommands ||= [] if list.empty?
75
+
73
76
  @subcommands = list
74
77
 
75
78
  define_method :run do |subcommand, *args|
@@ -85,7 +88,7 @@ module Travis
85
88
 
86
89
  attr_accessor :arguments, :config, :force_interactive, :formatter, :debug
87
90
  attr_reader :input, :output
88
- alias_method :debug?, :debug
91
+ alias debug? debug
89
92
 
90
93
  def initialize(options = {})
91
94
  @on_signal = []
@@ -113,7 +116,8 @@ module Travis
113
116
  end
114
117
 
115
118
  def write_to(io)
116
- io_was, self.output = output, io
119
+ io_was = output
120
+ self.output = io
117
121
  yield
118
122
  ensure
119
123
  self.output = io_was if io_was
@@ -126,13 +130,12 @@ module Travis
126
130
  error e.message
127
131
  end
128
132
 
129
- def setup
130
- end
133
+ def setup; end
131
134
 
132
135
  def last_check
133
136
  config['last_check'] ||= {
134
137
  # migrate from old values
135
- 'at' => config.delete('last_version_check'),
138
+ 'at' => config.delete('last_version_check'),
136
139
  'etag' => config.delete('etag')
137
140
  }
138
141
  end
@@ -144,38 +147,42 @@ module Travis
144
147
  return if skip_version_check?
145
148
  return if seconds_since < MINUTE
146
149
 
147
- case seconds_since
148
- when MINUTE .. HOUR then timeout = 0.5
149
- when HOUR .. DAY then timeout = 1.0
150
- when DAY .. WEEK then timeout = 2.0
151
- else timeout = 10.0
152
- end
150
+ timeout = case seconds_since
151
+ when MINUTE..HOUR then 0.5
152
+ when HOUR..DAY then 1.0
153
+ when DAY..WEEK then 2.0
154
+ else 10.0
155
+ end
153
156
 
154
157
  Timeout.timeout(timeout) do
155
- response = Faraday.get('https://rubygems.org/api/v1/gems/travis.json', {}, 'If-None-Match' => last_check['etag'].to_s)
158
+ response = Faraday.get('https://rubygems.org/api/v1/gems/travis.json', {},
159
+ 'If-None-Match' => last_check['etag'].to_s)
156
160
  last_check['etag'] = response.headers['etag']
157
161
  last_check['version'] = JSON.parse(response.body)['version'] if response.status == 200
158
162
  end
159
163
 
160
164
  last_check['at'] = Time.now.to_i
161
165
  unless Tools::System.recent_version? Travis::VERSION, last_check['version']
162
- warn "Outdated CLI version, run `gem install travis`."
166
+ warn 'Outdated CLI version, run `gem install travis`.'
163
167
  end
164
- rescue Timeout::Error, Faraday::ClientError => error
165
- debug "#{error.class}: #{error.message}"
166
- rescue JSON::ParserError => error
167
- warn "Unable to determine the most recent travis gem version. http://rubygems.org may be down."
168
+ rescue Timeout::Error, Faraday::ClientError => e
169
+ debug "#{e.class}: #{e.message}"
170
+ rescue JSON::ParserError
171
+ warn 'Unable to determine the most recent travis gem version. http://rubygems.org may be down.'
168
172
  end
169
173
 
170
174
  def check_completion
171
- return if skip_completion_check? or !interactive?
175
+ return if skip_completion_check? || !interactive?
172
176
 
173
177
  if config['checked_completion']
174
178
  Tools::Completion.update_completion if config['completion_version'] != Travis::VERSION
175
179
  else
176
180
  write_to($stderr) do
177
181
  next Tools::Completion.update_completion if Tools::Completion.completion_installed?
178
- next unless agree('Shell completion not installed. Would you like to install it now? ') { |q| q.default = "y" }
182
+ next unless agree('Shell completion not installed. Would you like to install it now? ') do |q|
183
+ q.default = 'y'
184
+ end
185
+
179
186
  Tools::Completion.install_completion
180
187
  end
181
188
  end
@@ -185,7 +192,8 @@ module Travis
185
192
  end
186
193
 
187
194
  def check_ruby
188
- return if RUBY_VERSION > '1.9.2' or skip_version_check?
195
+ return if (RUBY_VERSION > '1.9.2') || skip_version_check?
196
+
189
197
  warn "Your Ruby version is outdated, please consider upgrading, as we will drop support for #{RUBY_VERSION} soon!"
190
198
  end
191
199
 
@@ -202,20 +210,28 @@ module Travis
202
210
  store_config
203
211
  rescue Travis::Client::NotLoggedIn => e
204
212
  raise(e) if explode?
213
+
205
214
  error "#{e.message} - try running #{command("login#{endpoint_option}")}"
206
215
  rescue Travis::Client::RepositoryMigrated => e
207
- raise (e) if explode?
216
+ raise(e) if explode?
217
+
208
218
  error e.message
209
219
  rescue Travis::Client::NotFound => e
210
220
  raise(e) if explode?
221
+
211
222
  error "resource not found (#{e.message})"
212
223
  rescue Travis::Client::Error => e
213
224
  raise(e) if explode?
225
+
214
226
  error e.message
215
227
  rescue StandardError => e
216
228
  raise(e) if explode?
229
+
217
230
  message = e.message
218
- message += color("\nfor a full error report, run #{command("report#{endpoint_option}")}", :error) if interactive?
231
+ if interactive?
232
+ message += color("\nfor a full error report, run #{command("report#{endpoint_option}")}",
233
+ :error)
234
+ end
219
235
  store_error(e)
220
236
  error(message)
221
237
  end
@@ -225,7 +241,7 @@ module Travis
225
241
  end
226
242
 
227
243
  def usage
228
- "Usage: " << color(usage_for(command_name, :run), :command)
244
+ 'Usage: ' << color(usage_for(command_name, :run), :command)
229
245
  end
230
246
 
231
247
  def usage_for(prefix, method)
@@ -239,14 +255,14 @@ module Travis
239
255
  usage << " #{name}"
240
256
  end
241
257
  elsif method.arity != 0
242
- usage << " ..."
258
+ usage << ' ...'
243
259
  end
244
- usage << " [OPTIONS]"
260
+ usage << ' [OPTIONS]'
245
261
  end
246
262
 
247
- def help(info = "")
263
+ def help(info = '')
248
264
  parser.banner = usage
249
- self.class.description.sub(/./) { |c| c.upcase } + ".\n" + info + parser.to_s
265
+ "#{self.class.description.sub(/./) { |c| c.upcase }}.\n#{info}#{parser}"
250
266
  end
251
267
 
252
268
  def say(data, format = nil, style = nil)
@@ -255,6 +271,7 @@ module Travis
255
271
 
256
272
  def debug(line)
257
273
  return unless debug?
274
+
258
275
  write_to($stderr) do
259
276
  say color("** #{line}", :debug)
260
277
  end
@@ -262,11 +279,12 @@ module Travis
262
279
 
263
280
  def time(info, callback = Proc.new)
264
281
  return callback.call unless debug?
282
+
265
283
  start = Time.now
266
284
  debug(info)
267
285
  callback.call
268
286
  duration = Time.now - start
269
- debug(" took %.2g seconds" % duration)
287
+ debug(' took %.2g seconds' % duration)
270
288
  end
271
289
 
272
290
  def info(line)
@@ -293,135 +311,145 @@ module Travis
293
311
 
294
312
  private
295
313
 
296
- def store_error(exception)
297
- message = "An error occurred running `travis %s%s`:\n %p: %s\n" % [command_name, endpoint_option, exception.class, exception.message]
298
- exception.backtrace.each { |l| message << " from #{l}\n" }
299
- save_file("error.log", message)
300
- end
314
+ def store_error(exception)
315
+ message = format("An error occurred running `travis %s%s`:\n %p: %s\n", command_name, endpoint_option,
316
+ exception.class, exception.message)
317
+ exception.backtrace.each { |l| message << " from #{l}\n" }
318
+ save_file('error.log', message)
319
+ end
301
320
 
302
- def clear_error
303
- delete_file("error.log")
304
- end
321
+ def clear_error
322
+ delete_file('error.log')
323
+ end
305
324
 
306
- def setup_trap
307
- [:INT, :TERM].each do |signal|
308
- trap signal do
309
- @on_signal.each { |c| c.call }
310
- exit 1
311
- end
325
+ def setup_trap
326
+ %i[INT TERM].each do |signal|
327
+ trap signal do
328
+ @on_signal.each { |c| c.call }
329
+ exit 1
312
330
  end
313
331
  end
332
+ end
314
333
 
315
- def format(data, format = nil, style = nil)
316
- style ||= :important
317
- data = format % color(data, style) if format and interactive?
318
- data = data.gsub(/<\[\[/, '<%=').gsub(/\]\]>/, '%>')
319
- data.encode! 'utf-8' if data.respond_to? :encode!
320
- data
321
- end
334
+ def format(data, format = nil, style = nil)
335
+ style ||= :important
336
+ data = format % color(data, style) if format && interactive?
337
+ data = data.gsub(/<\[\[/, '<%=').gsub(/\]\]>/, '%>')
338
+ data.encode! 'utf-8' if data.respond_to? :encode!
339
+ data
340
+ end
322
341
 
323
- def template(*args)
324
- File.read(*args).split('__END__', 2)[1].strip
325
- end
342
+ def template(*args)
343
+ File.read(*args).split('__END__', 2)[1].strip
344
+ end
326
345
 
327
- def color(line, style)
328
- return line.to_s unless interactive?
329
- terminal.color(line || '???', Array(style).map(&:to_sym))
330
- end
346
+ def color(line, style)
347
+ return line.to_s unless interactive?
331
348
 
332
- def interactive?(io = output)
333
- return io.tty? if force_interactive.nil?
334
- force_interactive
335
- end
349
+ terminal.color(line || '???', Array(style).map(&:to_sym))
350
+ end
336
351
 
337
- def empty_line
338
- say "\n"
339
- end
352
+ def interactive?(io = output)
353
+ return io.tty? if force_interactive.nil?
340
354
 
341
- def command(name)
342
- color("#{File.basename($0)} #{name}", :command)
343
- end
355
+ force_interactive
356
+ end
344
357
 
345
- def success(line)
346
- say color(line, :success) if interactive?
347
- end
358
+ def empty_line
359
+ say "\n"
360
+ end
348
361
 
349
- def config_path(name)
350
- path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
351
- Dir.mkdir(path, 0700) unless File.directory? path
352
- File.join(path, name)
353
- end
362
+ def command(name)
363
+ color("#{File.basename($PROGRAM_NAME)} #{name}", :command)
364
+ end
354
365
 
355
- def load_file(name, default = nil)
356
- return default unless path = config_path(name) and File.exist? path
357
- debug "Loading %p" % path
358
- File.read(path)
359
- end
366
+ def success(line)
367
+ say color(line, :success) if interactive?
368
+ end
360
369
 
361
- def delete_file(name)
362
- return unless path = config_path(name) and File.exist? path
363
- debug "Deleting %p" % path
364
- File.delete(path)
365
- end
370
+ def config_path(name)
371
+ path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', Dir.home) }
372
+ Dir.mkdir(path, 0o700) unless File.directory? path
373
+ File.join(path, name)
374
+ end
366
375
 
367
- def save_file(name, content, read_only = false)
368
- path = config_path(name)
369
- debug "Storing %p" % path
370
- File.open(path, 'w') do |file|
371
- file.write(content.to_s)
372
- file.chmod(0600) if read_only
373
- end
374
- end
376
+ def load_file(name, default = nil)
377
+ return default unless (path = config_path(name)) && File.exist?(path)
375
378
 
376
- YAML_ERROR = defined?(Psych::SyntaxError) ? Psych::SyntaxError : ArgumentError
377
- def load_config
378
- @config = YAML.load load_file('config.yml', '{}')
379
- @config ||= {}
380
- @original_config = @config.dup
381
- rescue YAML_ERROR => error
382
- raise error if explode?
383
- warn "Broken config file: #{color config_path('config.yml'), :bold}"
384
- exit 1 unless interactive? and agree("Remove config file? ") { |q| q.default = "no" }
385
- @original_config, @config = {}, {}
386
- end
379
+ debug 'Loading %p' % path
380
+ File.read(path)
381
+ end
387
382
 
388
- def store_config
389
- save_file('config.yml', @config.to_yaml, true)
390
- end
383
+ def delete_file(name)
384
+ return unless (path = config_path(name)) && File.exist?(path)
391
385
 
392
- def check_arity(method, *args)
393
- return unless method.respond_to? :parameters
394
- method.parameters.each do |type, name|
395
- return if type == :rest
396
- wrong_args("few") unless args.shift or type == :opt or type == :block
397
- end
398
- wrong_args("many") if args.any?
399
- end
386
+ debug 'Deleting %p' % path
387
+ File.delete(path)
388
+ end
400
389
 
401
- def danger_zone?(message)
402
- agree(color("DANGER ZONE: ", [:red, :bold]) << message << " ") { |q| q.default = "no" }
390
+ def save_file(name, content, read_only = false)
391
+ path = config_path(name)
392
+ debug 'Storing %p' % path
393
+ File.open(path, 'w') do |file|
394
+ file.write(content.to_s)
395
+ file.chmod(0o600) if read_only
403
396
  end
397
+ end
404
398
 
405
- def write_file(file, content, force = false)
406
- error "#{file} already exists" unless write_file?(file, force)
407
- File.write(file, content)
408
- end
399
+ YAML_ERROR = defined?(Psych::SyntaxError) ? Psych::SyntaxError : ArgumentError
400
+ def load_config
401
+ @config = YAML.load load_file('config.yml', '{}')
402
+ @config ||= {}
403
+ @original_config = @config.dup
404
+ rescue YAML_ERROR => e
405
+ raise e if explode?
409
406
 
410
- def write_file?(file, force)
411
- return true if force or not File.exist?(file)
412
- return false unless interactive?
413
- danger_zone? "Override existing #{color(file, :info)}?"
414
- end
407
+ warn "Broken config file: #{color config_path('config.yml'), :bold}"
408
+ exit 1 unless interactive? && agree('Remove config file? ') { |q| q.default = 'no' }
409
+ @original_config = {}
410
+ @config = {}
411
+ end
415
412
 
416
- def wrong_args(quantity)
417
- error "too #{quantity} arguments" do
418
- say help
419
- end
413
+ def store_config
414
+ save_file('config.yml', @config.to_yaml, true)
415
+ end
416
+
417
+ def check_arity(method, *args)
418
+ return unless method.respond_to? :parameters
419
+
420
+ method.parameters.each do |type, _name|
421
+ return if type == :rest
422
+
423
+ wrong_args('few') unless args.shift || (type == :opt) || (type == :block)
420
424
  end
425
+ wrong_args('many') if args.any?
426
+ end
427
+
428
+ def danger_zone?(message)
429
+ agree(color('DANGER ZONE: ', %i[red bold]) << message << ' ') { |q| q.default = 'no' }
430
+ end
421
431
 
422
- def endpoint_option
423
- ""
432
+ def write_file(file, content, force = false)
433
+ error "#{file} already exists" unless write_file?(file, force)
434
+ File.write(file, content)
435
+ end
436
+
437
+ def write_file?(file, force)
438
+ return true if force || !File.exist?(file)
439
+ return false unless interactive?
440
+
441
+ danger_zone? "Override existing #{color(file, :info)}?"
442
+ end
443
+
444
+ def wrong_args(quantity)
445
+ error "too #{quantity} arguments" do
446
+ say help
424
447
  end
448
+ end
449
+
450
+ def endpoint_option
451
+ ''
452
+ end
425
453
  end
426
454
  end
427
455
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Console < ApiCommand
6
- description "interactive shell; requires `pry`"
8
+ description 'interactive shell; requires `pry`'
7
9
  on '-x', '--eval LINE', 'run line of ruby' do |c, line|
8
10
  c.instance_eval(line)
9
11
  exit
@@ -14,8 +16,8 @@ module Travis
14
16
 
15
17
  Object.send(:include, Client::Namespace.new(session))
16
18
  hooks = defined?(Pry::Hooks) ? Pry::Hooks.new : {}
17
- opts = {quiet: true, output: $stdout, hooks: hooks }
18
- opts.merge!({prompt: prompt}) if prompt
19
+ opts = { quiet: true, output: $stdout, hooks: }
20
+ opts.merge!({ prompt: }) if prompt
19
21
  binding.pry(opts)
20
22
  end
21
23
 
@@ -37,8 +39,6 @@ module Travis
37
39
  Pry::SIMPLE_PROMPT
38
40
  elsif defined?(Pry::Prompt)
39
41
  Pry::Prompt[:simple]
40
- else
41
- nil
42
42
  end
43
43
  end
44
44
  end
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Disable < RepoCommand
6
- description "disables a project"
8
+ description 'disables a project'
7
9
 
8
10
  def run
9
11
  authenticate
10
12
  repository.disable
11
- say "disabled", color("#{slug}: %s :(", :error)
13
+ say 'disabled', color("#{slug}: %s :(", :error)
12
14
  end
13
15
  end
14
16
  end
@@ -1,31 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/cli'
2
4
 
3
5
  module Travis
4
6
  module CLI
5
7
  class Enable < RepoCommand
6
- description "enables a project"
8
+ description 'enables a project'
7
9
  on('-s', '--skip-sync', "don't trigger a sync if the repo is unknown")
8
10
 
9
11
  def run
10
12
  authenticate
11
13
  error "not allowed to update service hook for #{color(repository.slug, :bold)}" unless repository.admin?
12
14
  repository.enable
13
- say "enabled", color("#{slug}: %s :)", :success)
15
+ say 'enabled', color("#{slug}: %s :)", :success)
14
16
  end
15
17
 
16
18
  private
17
19
 
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
20
+ def repository
21
+ repo(slug)
22
+ rescue Travis::Client::NotFound
23
+ unless skip_sync?
24
+ say 'repository not known to Travis CI (or no access?)'
25
+ say 'triggering sync: '
26
+ sync
27
+ say ' done'
28
28
  end
29
+ super
30
+ end
29
31
  end
30
32
  end
31
33
  end