travis 1.11.1 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/Rakefile +22 -20
- data/bin/travis +5 -3
- data/examples/org_overview.rb +2 -0
- data/examples/pro_auth.rb +3 -1
- data/examples/stream.rb +5 -3
- data/lib/travis/auto_login.rb +2 -0
- data/lib/travis/cli/accounts.rb +12 -9
- data/lib/travis/cli/api_command.rb +85 -81
- data/lib/travis/cli/branches.rb +8 -6
- data/lib/travis/cli/cache.rb +48 -44
- data/lib/travis/cli/cancel.rb +4 -2
- data/lib/travis/cli/command.rb +170 -142
- data/lib/travis/cli/console.rb +5 -5
- data/lib/travis/cli/disable.rb +4 -2
- data/lib/travis/cli/enable.rb +14 -12
- data/lib/travis/cli/encrypt.rb +57 -57
- data/lib/travis/cli/encrypt_file.rb +29 -18
- data/lib/travis/cli/endpoint.rb +9 -7
- data/lib/travis/cli/env.rb +13 -8
- data/lib/travis/cli/help.rb +10 -8
- data/lib/travis/cli/history.rb +19 -15
- data/lib/travis/cli/init.rb +27 -24
- data/lib/travis/cli/lint.rb +10 -8
- data/lib/travis/cli/login.rb +17 -11
- data/lib/travis/cli/logout.rb +4 -2
- data/lib/travis/cli/logs.rb +28 -19
- data/lib/travis/cli/monitor.rb +11 -8
- data/lib/travis/cli/open.rb +17 -14
- data/lib/travis/cli/parser.rb +2 -0
- data/lib/travis/cli/pubkey.rb +13 -11
- data/lib/travis/cli/raw.rb +4 -3
- data/lib/travis/cli/repo_command.rb +123 -112
- data/lib/travis/cli/report.rb +40 -33
- data/lib/travis/cli/repos.rb +14 -9
- data/lib/travis/cli/requests.rb +13 -12
- data/lib/travis/cli/restart.rb +4 -2
- data/lib/travis/cli/settings.rb +41 -35
- data/lib/travis/cli/setup/anynines.rb +7 -6
- data/lib/travis/cli/setup/appfog.rb +6 -4
- data/lib/travis/cli/setup/artifacts.rb +7 -5
- data/lib/travis/cli/setup/biicode.rb +6 -4
- data/lib/travis/cli/setup/cloud_66.rb +6 -4
- data/lib/travis/cli/setup/cloud_control.rb +8 -6
- data/lib/travis/cli/setup/cloud_files.rb +7 -5
- data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
- data/lib/travis/cli/setup/code_deploy.rb +33 -29
- data/lib/travis/cli/setup/deis.rb +8 -6
- data/lib/travis/cli/setup/divshot.rb +20 -18
- data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
- data/lib/travis/cli/setup/engine_yard.rb +9 -7
- data/lib/travis/cli/setup/gcs.rb +9 -7
- data/lib/travis/cli/setup/hackage.rb +6 -4
- data/lib/travis/cli/setup/heroku.rb +10 -4
- data/lib/travis/cli/setup/modulus.rb +5 -3
- data/lib/travis/cli/setup/ninefold.rb +7 -5
- data/lib/travis/cli/setup/nodejitsu.rb +6 -4
- data/lib/travis/cli/setup/npm.rb +6 -4
- data/lib/travis/cli/setup/open_shift.rb +8 -6
- data/lib/travis/cli/setup/opsworks.rb +24 -22
- data/lib/travis/cli/setup/pypi.rb +7 -5
- data/lib/travis/cli/setup/releases.rb +6 -6
- data/lib/travis/cli/setup/ruby_gems.rb +7 -5
- data/lib/travis/cli/setup/s3.rb +12 -8
- data/lib/travis/cli/setup/sauce_connect.rb +7 -5
- data/lib/travis/cli/setup/service.rb +36 -25
- data/lib/travis/cli/setup.rb +7 -3
- data/lib/travis/cli/show.rb +10 -8
- data/lib/travis/cli/sshkey.rb +31 -27
- data/lib/travis/cli/status.rb +5 -3
- data/lib/travis/cli/sync.rb +9 -7
- data/lib/travis/cli/token.rb +4 -2
- data/lib/travis/cli/version.rb +4 -3
- data/lib/travis/cli/whatsup.rb +10 -8
- data/lib/travis/cli/whoami.rb +2 -2
- data/lib/travis/cli.rb +39 -36
- data/lib/travis/client/account.rb +8 -6
- data/lib/travis/client/artifact.rb +16 -12
- data/lib/travis/client/auto_login.rb +7 -4
- data/lib/travis/client/broadcast.rb +2 -0
- data/lib/travis/client/build.rb +7 -3
- data/lib/travis/client/cache.rb +4 -2
- data/lib/travis/client/commit.rb +5 -2
- data/lib/travis/client/entity.rb +50 -46
- data/lib/travis/client/env_var.rb +13 -8
- data/lib/travis/client/error.rb +5 -3
- data/lib/travis/client/has_uuid.rb +3 -1
- data/lib/travis/client/job.rb +8 -3
- data/lib/travis/client/lint_result.rb +2 -0
- data/lib/travis/client/listener.rb +70 -55
- data/lib/travis/client/methods.rb +10 -5
- data/lib/travis/client/namespace.rb +20 -16
- data/lib/travis/client/not_loadable.rb +3 -1
- data/lib/travis/client/repository.rb +34 -22
- data/lib/travis/client/request.rb +5 -2
- data/lib/travis/client/restartable.rb +2 -0
- data/lib/travis/client/session.rb +118 -88
- data/lib/travis/client/settings.rb +8 -3
- data/lib/travis/client/singleton_setting.rb +2 -0
- data/lib/travis/client/ssh_key.rb +2 -0
- data/lib/travis/client/states.rb +8 -6
- data/lib/travis/client/user.rb +2 -0
- data/lib/travis/client/weak_entity.rb +6 -3
- data/lib/travis/client.rb +4 -1
- data/lib/travis/pro/auto_login.rb +2 -0
- data/lib/travis/pro.rb +2 -0
- data/lib/travis/tools/assets.rb +6 -3
- data/lib/travis/tools/completion.rb +10 -6
- data/lib/travis/tools/formatter.rb +20 -14
- data/lib/travis/tools/github.rb +59 -49
- data/lib/travis/tools/notification.rb +18 -13
- data/lib/travis/tools/safe_string.rb +4 -1
- data/lib/travis/tools/ssl_key.rb +5 -2
- data/lib/travis/tools/system.rb +11 -6
- data/lib/travis/version.rb +3 -1
- data/lib/travis.rb +3 -1
- data/spec/cli/api_command_spec.rb +11 -8
- data/spec/cli/cancel_spec.rb +2 -4
- data/spec/cli/encrypt_file_spec.rb +9 -7
- data/spec/cli/encrypt_spec.rb +19 -17
- data/spec/cli/endpoint_spec.rb +12 -10
- data/spec/cli/help_spec.rb +14 -12
- data/spec/cli/history_spec.rb +2 -0
- data/spec/cli/init_spec.rb +35 -33
- data/spec/cli/logs_spec.rb +2 -0
- data/spec/cli/open_spec.rb +6 -4
- data/spec/cli/repo_command_spec.rb +8 -4
- data/spec/cli/restart_spec.rb +2 -4
- data/spec/cli/setup/service_spec.rb +17 -18
- data/spec/cli/setup_spec.rb +2 -4
- data/spec/cli/show_spec.rb +4 -2
- data/spec/cli/status_spec.rb +7 -5
- data/spec/cli/token_spec.rb +7 -5
- data/spec/cli/version_spec.rb +2 -0
- data/spec/cli/whoami_spec.rb +9 -7
- data/spec/client/account_spec.rb +28 -20
- data/spec/client/auto_login_spec.rb +12 -9
- data/spec/client/broadcast_spec.rb +5 -3
- data/spec/client/build_spec.rb +28 -24
- data/spec/client/commit_spec.rb +17 -14
- data/spec/client/job_spec.rb +27 -23
- data/spec/client/methods_spec.rb +8 -4
- data/spec/client/namespace_spec.rb +8 -4
- data/spec/client/repository_spec.rb +33 -30
- data/spec/client/session_spec.rb +71 -67
- data/spec/client/user_spec.rb +13 -10
- data/spec/client_spec.rb +6 -4
- data/spec/pro_spec.rb +5 -3
- data/spec/spec_helper.rb +3 -1
- data/spec/support/fake_api.rb +662 -662
- data/spec/support/fake_github.rb +6 -3
- data/spec/support/helpers.rb +13 -8
- data/spec/travis_spec.rb +5 -3
- data/travis.gemspec +400 -399
- metadata +30 -50
data/lib/travis/cli/command.rb
CHANGED
@@ -15,21 +15,23 @@ module Travis
|
|
15
15
|
class Command
|
16
16
|
MINUTE = 60
|
17
17
|
HOUR = 3600
|
18
|
-
DAY =
|
19
|
-
WEEK =
|
18
|
+
DAY = 86_400
|
19
|
+
WEEK = 604_800
|
20
20
|
|
21
21
|
include Tools::Assets
|
22
|
-
extend
|
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] = [
|
28
|
-
cs[:error] = [
|
29
|
-
cs[:important] = [
|
30
|
-
cs[:success] = [
|
31
|
-
cs[:info] = [
|
32
|
-
cs[:debug] = [
|
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',
|
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
|
-
|
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
|
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'
|
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
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
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', {},
|
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
|
166
|
+
warn 'Outdated CLI version, run `gem install travis`.'
|
163
167
|
end
|
164
|
-
rescue Timeout::Error, Faraday::ClientError =>
|
165
|
-
debug "#{
|
166
|
-
rescue JSON::ParserError
|
167
|
-
warn
|
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?
|
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? ')
|
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'
|
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
|
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
|
-
|
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
|
-
|
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 <<
|
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 }
|
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(
|
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
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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
|
-
|
303
|
-
|
304
|
-
|
321
|
+
def clear_error
|
322
|
+
delete_file('error.log')
|
323
|
+
end
|
305
324
|
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
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
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
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
|
-
|
324
|
-
|
325
|
-
|
342
|
+
def template(*args)
|
343
|
+
File.read(*args).split('__END__', 2)[1].strip
|
344
|
+
end
|
326
345
|
|
327
|
-
|
328
|
-
|
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
|
-
|
333
|
-
|
334
|
-
force_interactive
|
335
|
-
end
|
349
|
+
terminal.color(line || '???', Array(style).map(&:to_sym))
|
350
|
+
end
|
336
351
|
|
337
|
-
|
338
|
-
|
339
|
-
end
|
352
|
+
def interactive?(io = output)
|
353
|
+
return io.tty? if force_interactive.nil?
|
340
354
|
|
341
|
-
|
342
|
-
|
343
|
-
end
|
355
|
+
force_interactive
|
356
|
+
end
|
344
357
|
|
345
|
-
|
346
|
-
|
347
|
-
|
358
|
+
def empty_line
|
359
|
+
say "\n"
|
360
|
+
end
|
348
361
|
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
File.join(path, name)
|
353
|
-
end
|
362
|
+
def command(name)
|
363
|
+
color("#{File.basename($PROGRAM_NAME)} #{name}", :command)
|
364
|
+
end
|
354
365
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
File.read(path)
|
359
|
-
end
|
366
|
+
def success(line)
|
367
|
+
say color(line, :success) if interactive?
|
368
|
+
end
|
360
369
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
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
|
-
|
368
|
-
|
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
|
-
|
377
|
-
|
378
|
-
|
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
|
-
|
389
|
-
|
390
|
-
end
|
383
|
+
def delete_file(name)
|
384
|
+
return unless (path = config_path(name)) && File.exist?(path)
|
391
385
|
|
392
|
-
|
393
|
-
|
394
|
-
|
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
|
-
|
402
|
-
|
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
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
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
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
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
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
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
|
-
|
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
|
data/lib/travis/cli/console.rb
CHANGED
@@ -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
|
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:
|
18
|
-
opts.merge!({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
|
data/lib/travis/cli/disable.rb
CHANGED
@@ -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
|
8
|
+
description 'disables a project'
|
7
9
|
|
8
10
|
def run
|
9
11
|
authenticate
|
10
12
|
repository.disable
|
11
|
-
say
|
13
|
+
say 'disabled', color("#{slug}: %s :(", :error)
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
data/lib/travis/cli/enable.rb
CHANGED
@@ -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
|
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
|
15
|
+
say 'enabled', color("#{slug}: %s :)", :success)
|
14
16
|
end
|
15
17
|
|
16
18
|
private
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|