travis 1.11.0 → 1.12.0
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.
- checksums.yaml +4 -4
- data/README.md +18 -4
- 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 -28
- 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
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client'
|
2
4
|
require 'travis/version'
|
3
5
|
|
4
6
|
require 'faraday'
|
5
|
-
require 'faraday_middleware'
|
6
7
|
require 'travis/tools/system'
|
7
8
|
require 'travis/tools/assets'
|
9
|
+
require 'faraday/rack'
|
8
10
|
|
9
11
|
begin
|
10
|
-
require 'typhoeus
|
12
|
+
require 'faraday/typhoeus' unless Travis::Tools::System.windows?
|
11
13
|
rescue LoadError
|
12
14
|
end
|
13
15
|
|
@@ -16,14 +18,14 @@ require 'json'
|
|
16
18
|
module Travis
|
17
19
|
module Client
|
18
20
|
class Session
|
19
|
-
PRIMITIVE = [nil, false, true]
|
20
|
-
SSL_OPTIONS = { :
|
21
|
+
PRIMITIVE = [nil, false, true].freeze
|
22
|
+
SSL_OPTIONS = { ca_file: Tools::Assets['cacert.pem'] }
|
21
23
|
|
22
24
|
include Methods
|
23
25
|
attr_reader :connection, :headers, :access_token, :instruments, :faraday_adapter, :agent_info, :ssl
|
24
26
|
attr_accessor :debug_http
|
25
27
|
|
26
|
-
def initialize(options = Travis::Client::
|
28
|
+
def initialize(options = Travis::Client::COM_URI)
|
27
29
|
@headers = {}
|
28
30
|
@cache = {}
|
29
31
|
@instruments = []
|
@@ -32,10 +34,11 @@ module Travis
|
|
32
34
|
@faraday_adapter = defined?(Typhoeus) ? :typhoeus : :net_http
|
33
35
|
@ssl = SSL_OPTIONS
|
34
36
|
|
35
|
-
options = { :
|
37
|
+
options = { uri: options } unless options.respond_to? :each_pair
|
36
38
|
options.each_pair { |key, value| public_send("#{key}=", value) }
|
37
39
|
|
38
|
-
raise ArgumentError,
|
40
|
+
raise ArgumentError, 'neither :uri nor :connection specified' unless connection
|
41
|
+
|
39
42
|
headers['Accept'] = 'application/vnd.travis-ci.2+json'
|
40
43
|
set_user_agent
|
41
44
|
check_ssl
|
@@ -57,7 +60,7 @@ module Travis
|
|
57
60
|
|
58
61
|
def uri=(uri)
|
59
62
|
clear_cache!
|
60
|
-
self.connection = Faraday.new(:
|
63
|
+
self.connection = Faraday.new(url: uri, ssl:) do |faraday|
|
61
64
|
faraday.request :url_encoded
|
62
65
|
faraday.request :retry
|
63
66
|
faraday.response :logger if debug_http
|
@@ -93,21 +96,27 @@ module Travis
|
|
93
96
|
end
|
94
97
|
|
95
98
|
def find_one(entity, id = nil)
|
96
|
-
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many)
|
99
|
+
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) && entity.many
|
97
100
|
return create_entity(entity, entity.id_field => id) if entity.id? id
|
101
|
+
|
98
102
|
cached(entity, :by, id) { fetch_one(entity, id) }
|
99
103
|
end
|
100
104
|
|
101
105
|
def find_many(entity, args = {})
|
102
|
-
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many)
|
106
|
+
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) && entity.many
|
107
|
+
|
103
108
|
cached(entity, :many, args) { fetch_many(entity, args) }
|
104
109
|
end
|
105
110
|
|
106
111
|
def find_one_or_many(entity, args = nil)
|
107
|
-
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many)
|
112
|
+
raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) && entity.many
|
113
|
+
|
108
114
|
cached(entity, :one_or_many, args) do
|
109
|
-
path
|
110
|
-
|
115
|
+
path = "/#{entity.many}"
|
116
|
+
unless args.is_a? Hash
|
117
|
+
path = "#{path}/#{args}"
|
118
|
+
args = {}
|
119
|
+
end
|
111
120
|
result = get(path, args)
|
112
121
|
one = result[entity.one]
|
113
122
|
|
@@ -157,8 +166,9 @@ module Travis
|
|
157
166
|
def preload(list)
|
158
167
|
list.group_by(&:class).each do |type, instances|
|
159
168
|
next unless type.preloadable?
|
169
|
+
|
160
170
|
ids = instances.map { |e| e.id unless e.complete? }.compact
|
161
|
-
find_many(type, :
|
171
|
+
find_many(type, ids:) if ids.any?
|
162
172
|
end
|
163
173
|
list
|
164
174
|
end
|
@@ -204,32 +214,40 @@ module Travis
|
|
204
214
|
end
|
205
215
|
|
206
216
|
def raw(verb, url, *args)
|
207
|
-
url = url.sub(
|
217
|
+
url = url.sub(%r{^/}, '')
|
208
218
|
result = instrumented(verb.to_s.upcase, url, *args) do
|
209
|
-
if url !~ /^https?:/
|
219
|
+
if url !~ (/^https?:/) || url.start_with?(api_endpoint)
|
210
220
|
connection.public_send(verb, url, *args)
|
211
221
|
else
|
212
|
-
Faraday.public_send(verb, url, *args) { |r| r.headers.delete(
|
222
|
+
Faraday.public_send(verb, url, *args) { |r| r.headers.delete('Authorization') }
|
213
223
|
end
|
214
224
|
end
|
215
225
|
|
216
226
|
case result.status
|
217
227
|
when 0 then raise Travis::Client::SSLError, 'SSL error: could not verify peer'
|
218
|
-
when 200..299 then
|
228
|
+
when 200..299 then begin
|
229
|
+
JSON.parse(result.body)
|
230
|
+
rescue StandardError
|
231
|
+
result.body
|
232
|
+
end
|
219
233
|
when 301, 303 then raw(:get, result.headers['Location'])
|
220
234
|
when 302, 307, 308 then raw(verb, result.headers['Location'])
|
221
|
-
when 401 then raise Travis::Client::NotLoggedIn,
|
222
|
-
when 403
|
223
|
-
body =
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
raise Travis::Client::NotLoggedIn, 'invalid access token'
|
235
|
+
when 401 then raise Travis::Client::NotLoggedIn, 'not logged in'
|
236
|
+
when 403
|
237
|
+
body = begin
|
238
|
+
JSON.parse(result.body)
|
239
|
+
rescue StandardError
|
240
|
+
{}
|
228
241
|
end
|
242
|
+
raise Travis::Client::RepositoryMigrated, body['error_message'] if body['error_type'] == 'migrated_repository'
|
243
|
+
|
244
|
+
raise Travis::Client::NotLoggedIn, 'invalid access token'
|
245
|
+
|
229
246
|
when 404 then raise Travis::Client::NotFound, result.body
|
230
247
|
when 422 then raise Travis::Client::ValidationFailed, result.body
|
231
|
-
when 400..499 then raise Travis::Client::Error,
|
232
|
-
when 500..599 then raise Travis::Client::Error,
|
248
|
+
when 400..499 then raise Travis::Client::Error, format('%s: %p', result.status, result.body)
|
249
|
+
when 500..599 then raise Travis::Client::Error,
|
250
|
+
format('server error (%s: %p)', result.status, result.body)
|
233
251
|
else raise Travis::Client::Error, "unhandled status code #{result.status}"
|
234
252
|
end
|
235
253
|
end
|
@@ -264,83 +282,95 @@ module Travis
|
|
264
282
|
|
265
283
|
private
|
266
284
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
285
|
+
def set_user_agent
|
286
|
+
adapter = faraday_adapter.is_a?(Array) ? faraday_adapter.first : faraday_adapter
|
287
|
+
adapter = adapter.to_s.capitalize.gsub(/_http_(.)/) do
|
288
|
+
"::HTTP::#{::Regexp.last_match(1).upcase}"
|
289
|
+
end.gsub(/_http/, '::HTTP')
|
290
|
+
headers['User-Agent'] =
|
291
|
+
"Travis/#{Travis::VERSION} (#{Travis::Tools::System.description(agent_info)}) Faraday/#{Faraday::VERSION} #{adapter}/#{adapter_version(adapter)}"
|
292
|
+
end
|
272
293
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
294
|
+
def adapter_version(adapter)
|
295
|
+
version = Object.const_get(adapter).const_get('VERSION')
|
296
|
+
[*version].join('.')
|
297
|
+
rescue Exception
|
298
|
+
'unknown'
|
299
|
+
end
|
279
300
|
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
301
|
+
def instrumented(name, *args)
|
302
|
+
name = [name, *args.map(&:inspect)].join(' ') if args.any?
|
303
|
+
result = nil
|
304
|
+
chain = instruments + [proc { |_n, _l| result = yield }]
|
305
|
+
lift = proc { chain.shift.call(name, lift) }
|
306
|
+
lift.call
|
307
|
+
result
|
308
|
+
end
|
288
309
|
|
289
|
-
|
290
|
-
|
291
|
-
data = { type.id_field => data } if type.id? data
|
292
|
-
id = type.cast_id(data.fetch(type.id_field)) unless type.weak?
|
293
|
-
entity = id ? cached(type, :id, id) { type.new(self, id) } : type.new(self, nil)
|
294
|
-
entity.update_attributes(data)
|
295
|
-
entity
|
296
|
-
end
|
310
|
+
def create_entity(type, data)
|
311
|
+
return data if primitive?(data)
|
297
312
|
|
298
|
-
|
299
|
-
|
300
|
-
|
313
|
+
data = { type.id_field => data } if type.id? data
|
314
|
+
id = type.cast_id(data.fetch(type.id_field)) unless type.weak?
|
315
|
+
entity = id ? cached(type, :id, id) { type.new(self, id) } : type.new(self, nil)
|
316
|
+
entity.update_attributes(data)
|
317
|
+
entity
|
318
|
+
end
|
301
319
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
end
|
320
|
+
def primitive?(data)
|
321
|
+
PRIMITIVE.include? data
|
322
|
+
end
|
306
323
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
324
|
+
def error_message(e)
|
325
|
+
message = begin
|
326
|
+
e.response[:body].to_str
|
327
|
+
rescue StandardError
|
328
|
+
e.message
|
311
329
|
end
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
end
|
330
|
+
begin
|
331
|
+
JSON.parse(message).fetch('error').fetch('message')
|
332
|
+
rescue StandardError
|
333
|
+
message
|
317
334
|
end
|
335
|
+
end
|
318
336
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
end
|
337
|
+
def reset_entities
|
338
|
+
subcaches do |subcache|
|
339
|
+
subcache[:id].each_value { |e| e.attributes.clear } if subcache.include? :id
|
323
340
|
end
|
341
|
+
end
|
324
342
|
|
325
|
-
|
326
|
-
|
343
|
+
def clear_find_cache
|
344
|
+
subcaches do |subcache|
|
345
|
+
subcache.delete_if { |k, _v| k != :id }
|
327
346
|
end
|
347
|
+
end
|
328
348
|
|
329
|
-
|
330
|
-
|
349
|
+
def subcaches
|
350
|
+
@cache.each_value do |subcache|
|
351
|
+
yield subcache if subcache.is_a? Hash
|
331
352
|
end
|
353
|
+
end
|
332
354
|
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
cache[last] ||= yield
|
337
|
-
end
|
355
|
+
def fetch_one(entity, id = nil)
|
356
|
+
get("/#{entity.base_path}/#{id}")[entity.one]
|
357
|
+
end
|
338
358
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
359
|
+
def fetch_many(entity, params = {})
|
360
|
+
get("/#{entity.base_path}/", params)[entity.many]
|
361
|
+
end
|
362
|
+
|
363
|
+
def cached(*keys)
|
364
|
+
last = keys.pop
|
365
|
+
cache = keys.inject(@cache) { |store, key| store[key] ||= {} }
|
366
|
+
cache[last] ||= yield
|
367
|
+
end
|
368
|
+
|
369
|
+
def check_ssl
|
370
|
+
raw(:head, '/') if ssl == SSL_OPTIONS
|
371
|
+
rescue Exception => e
|
372
|
+
self.ssl = {} if e.instance_of?(Travis::Client::SSLError)
|
373
|
+
end
|
344
374
|
end
|
345
375
|
end
|
346
376
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client/weak_entity'
|
2
4
|
require 'json'
|
3
5
|
|
@@ -5,14 +7,17 @@ module Travis
|
|
5
7
|
module Client
|
6
8
|
class Settings < WeakEntity
|
7
9
|
attr_accessor :repository
|
10
|
+
|
8
11
|
# @!parse attr_reader :builds_only_with_travis_yml, :build_pushes, :build_pull_requests, :maximum_number_of_builds, :auto_cancel_pushes, :auto_cancel_pull_requests
|
9
|
-
attributes :builds_only_with_travis_yml, :build_pushes, :build_pull_requests, :maximum_number_of_builds,
|
12
|
+
attributes :builds_only_with_travis_yml, :build_pushes, :build_pull_requests, :maximum_number_of_builds,
|
13
|
+
:auto_cancel_pushes, :auto_cancel_pull_requests
|
10
14
|
one :settings
|
11
15
|
many :settings
|
12
16
|
|
13
17
|
def save
|
14
|
-
raise
|
15
|
-
|
18
|
+
raise 'repository unknown' unless repository
|
19
|
+
|
20
|
+
result = session.patch("/repos/#{repository.id}/settings", JSON.dump('settings' => attributes))
|
16
21
|
attributes.replace(result['settings'].attributes)
|
17
22
|
self
|
18
23
|
end
|
data/lib/travis/client/states.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client'
|
2
4
|
|
3
5
|
module Travis
|
4
6
|
module Client
|
5
7
|
module States
|
6
|
-
STATES
|
8
|
+
STATES = %w[created queued received started passed failed errored canceled ready].freeze
|
7
9
|
|
8
10
|
def ready?
|
9
11
|
state == 'ready'
|
@@ -11,7 +13,7 @@ module Travis
|
|
11
13
|
|
12
14
|
def pending?
|
13
15
|
check_state
|
14
|
-
%w[created started queued received
|
16
|
+
%w[created started queued received].include? state
|
15
17
|
end
|
16
18
|
|
17
19
|
def started?
|
@@ -30,7 +32,7 @@ module Travis
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def finished?
|
33
|
-
|
35
|
+
!pending?
|
34
36
|
end
|
35
37
|
|
36
38
|
def passed?
|
@@ -90,9 +92,9 @@ module Travis
|
|
90
92
|
|
91
93
|
private
|
92
94
|
|
93
|
-
|
94
|
-
|
95
|
-
|
95
|
+
def check_state
|
96
|
+
raise Error, format('unknown state %p for %p', state, self) unless STATES.include? state
|
97
|
+
end
|
96
98
|
end
|
97
99
|
end
|
98
100
|
end
|
data/lib/travis/client/user.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client'
|
2
4
|
|
3
5
|
module Travis
|
@@ -10,7 +12,7 @@ module Travis
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def self.id_field
|
13
|
-
raise
|
15
|
+
raise 'weak entities do not have id fields'
|
14
16
|
end
|
15
17
|
|
16
18
|
def self.id?(object)
|
@@ -19,8 +21,9 @@ module Travis
|
|
19
21
|
|
20
22
|
def self.cast_id(object)
|
21
23
|
return object if id? object
|
22
|
-
|
24
|
+
|
25
|
+
raise 'weak entities do not have id fields'
|
23
26
|
end
|
24
27
|
end
|
25
28
|
end
|
26
|
-
end
|
29
|
+
end
|
data/lib/travis/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/client/error'
|
2
4
|
require 'travis/client/states'
|
3
5
|
require 'travis/client/restartable'
|
@@ -26,11 +28,12 @@ require 'travis/client/lint_result'
|
|
26
28
|
|
27
29
|
module Travis
|
28
30
|
module Client
|
31
|
+
|
29
32
|
ORG_URI = 'https://api.travis-ci.org/'
|
30
33
|
COM_URI = 'https://api.travis-ci.com/'
|
31
34
|
|
32
35
|
def self.new(options = {})
|
33
|
-
options[:uri] ||=
|
36
|
+
options[:uri] ||= COM_URI if options.is_a?(Hash) && !(options['uri'])
|
34
37
|
Session.new(options)
|
35
38
|
end
|
36
39
|
end
|
data/lib/travis/pro.rb
CHANGED
data/lib/travis/tools/assets.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pathname'
|
2
4
|
module Travis
|
3
5
|
module Tools
|
4
6
|
module Assets
|
5
|
-
BASE = File.expand_path('
|
6
|
-
|
7
|
+
BASE = File.expand_path('../../../assets', __dir__)
|
8
|
+
|
9
|
+
module_function
|
7
10
|
|
8
11
|
def asset_path(file)
|
9
12
|
Pathname.glob(File.expand_path(file, BASE)).tap do |x|
|
10
|
-
raise Travis::Client::AssetNotFound
|
13
|
+
raise Travis::Client::AssetNotFound, file if x.empty?
|
11
14
|
end.first.to_s
|
12
15
|
end
|
13
16
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'travis/tools/assets'
|
2
4
|
require 'travis/cli'
|
3
5
|
require 'fileutils'
|
@@ -8,7 +10,8 @@ module Travis
|
|
8
10
|
module Completion
|
9
11
|
RCS = ['.zshrc', '.bashrc'].map { |f| File.expand_path(f, ENV['HOME']) }
|
10
12
|
include FileUtils
|
11
|
-
|
13
|
+
|
14
|
+
module_function
|
12
15
|
|
13
16
|
def config_path
|
14
17
|
ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
|
@@ -20,12 +23,13 @@ module Travis
|
|
20
23
|
|
21
24
|
def install_completion
|
22
25
|
update_completion
|
23
|
-
source =
|
26
|
+
source = 'source ' << cmp_file
|
24
27
|
|
25
28
|
RCS.each do |file|
|
26
|
-
next unless File.exist?
|
29
|
+
next unless File.exist?(file) && File.writable?(file)
|
27
30
|
next if File.read(file).include? source
|
28
|
-
|
31
|
+
|
32
|
+
File.open(file, 'a') { |f| f.puts('', '# added by travis gem', "[ ! -s #{cmp_file} ] || #{source}") }
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
@@ -35,9 +39,9 @@ module Travis
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def completion_installed?
|
38
|
-
source =
|
42
|
+
source = 'source ' << config_path
|
39
43
|
RCS.each do |file|
|
40
|
-
next unless File.exist?
|
44
|
+
next unless File.exist?(file) && File.writable?(file)
|
41
45
|
return false unless File.read(file).include? source
|
42
46
|
end
|
43
47
|
true
|
@@ -1,30 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'time'
|
2
4
|
|
3
5
|
module Travis
|
4
6
|
module Tools
|
5
7
|
class Formatter
|
6
8
|
DAY = 24 * 60 * 60
|
7
|
-
TIME_FORMAT =
|
8
|
-
CONFIG_KEYS = [
|
9
|
+
TIME_FORMAT = '%Y-%m-%d %H:%M:%S'
|
10
|
+
CONFIG_KEYS = %w[rvm gemfile env jdk otp_release php node_js perl python scala
|
11
|
+
compiler os].freeze
|
9
12
|
|
10
13
|
def duration(seconds, suffix = nil)
|
11
|
-
return
|
14
|
+
return 'none' if seconds.nil?
|
15
|
+
|
12
16
|
seconds = (Time.now - seconds).to_i if seconds.is_a? Time
|
13
17
|
output = []
|
14
18
|
minutes, seconds = seconds.divmod(60)
|
15
19
|
hours, minutes = minutes.divmod(60)
|
16
|
-
output << "#{hours
|
17
|
-
output << "#{minutes} min" if minutes
|
18
|
-
output << "#{seconds} sec" if seconds
|
20
|
+
output << "#{hours} hrs" if hours.positive?
|
21
|
+
output << "#{minutes} min" if minutes.positive?
|
22
|
+
output << "#{seconds} sec" if seconds.positive? || output.empty?
|
19
23
|
output << suffix if suffix
|
20
|
-
output.join(
|
24
|
+
output.join(' ')
|
21
25
|
end
|
22
26
|
|
23
|
-
def file_size(input, human
|
27
|
+
def file_size(input, human: true)
|
24
28
|
return "#{input} B" unless human
|
25
|
-
|
29
|
+
|
30
|
+
format = 'B'
|
26
31
|
iec = %w[KiB MiB GiB TiB PiB EiB ZiB YiB]
|
27
|
-
while human
|
32
|
+
while human && (input > 512) && iec.any?
|
28
33
|
input /= 1024.0
|
29
34
|
format = iec.shift
|
30
35
|
end
|
@@ -33,8 +38,9 @@ module Travis
|
|
33
38
|
end
|
34
39
|
|
35
40
|
def time(time)
|
36
|
-
return
|
37
|
-
|
41
|
+
return 'not yet' if time.nil? # or time > Time.now
|
42
|
+
|
43
|
+
# return duration(time, "ago") if Time.now - time < DAY
|
38
44
|
time.localtime.strftime(TIME_FORMAT)
|
39
45
|
end
|
40
46
|
|
@@ -43,8 +49,8 @@ module Travis
|
|
43
49
|
config.each_pair do |key, value|
|
44
50
|
output << "#{key}: #{value}" if CONFIG_KEYS.include? key
|
45
51
|
end
|
46
|
-
output.join(
|
52
|
+
output.join(', ')
|
47
53
|
end
|
48
54
|
end
|
49
55
|
end
|
50
|
-
end
|
56
|
+
end
|