travis 1.11.1 → 1.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +34 -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 +11 -9
  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/regenerate_token.rb +15 -0
  35. data/lib/travis/cli/remove_token.rb +15 -0
  36. data/lib/travis/cli/repo_command.rb +123 -112
  37. data/lib/travis/cli/report.rb +40 -33
  38. data/lib/travis/cli/repos.rb +14 -9
  39. data/lib/travis/cli/requests.rb +13 -12
  40. data/lib/travis/cli/restart.rb +4 -2
  41. data/lib/travis/cli/settings.rb +41 -35
  42. data/lib/travis/cli/setup/anynines.rb +7 -6
  43. data/lib/travis/cli/setup/appfog.rb +6 -4
  44. data/lib/travis/cli/setup/artifacts.rb +7 -5
  45. data/lib/travis/cli/setup/biicode.rb +6 -4
  46. data/lib/travis/cli/setup/cloud_66.rb +6 -4
  47. data/lib/travis/cli/setup/cloud_control.rb +8 -6
  48. data/lib/travis/cli/setup/cloud_files.rb +7 -5
  49. data/lib/travis/cli/setup/cloud_foundry.rb +9 -7
  50. data/lib/travis/cli/setup/code_deploy.rb +33 -29
  51. data/lib/travis/cli/setup/deis.rb +8 -6
  52. data/lib/travis/cli/setup/divshot.rb +20 -18
  53. data/lib/travis/cli/setup/elastic_beanstalk.rb +10 -8
  54. data/lib/travis/cli/setup/engine_yard.rb +9 -7
  55. data/lib/travis/cli/setup/gcs.rb +9 -7
  56. data/lib/travis/cli/setup/hackage.rb +6 -4
  57. data/lib/travis/cli/setup/heroku.rb +10 -4
  58. data/lib/travis/cli/setup/modulus.rb +5 -3
  59. data/lib/travis/cli/setup/ninefold.rb +7 -5
  60. data/lib/travis/cli/setup/nodejitsu.rb +6 -4
  61. data/lib/travis/cli/setup/npm.rb +6 -4
  62. data/lib/travis/cli/setup/open_shift.rb +8 -6
  63. data/lib/travis/cli/setup/opsworks.rb +24 -22
  64. data/lib/travis/cli/setup/pypi.rb +7 -5
  65. data/lib/travis/cli/setup/releases.rb +6 -6
  66. data/lib/travis/cli/setup/ruby_gems.rb +7 -5
  67. data/lib/travis/cli/setup/s3.rb +12 -8
  68. data/lib/travis/cli/setup/sauce_connect.rb +7 -5
  69. data/lib/travis/cli/setup/service.rb +36 -25
  70. data/lib/travis/cli/setup.rb +7 -3
  71. data/lib/travis/cli/show.rb +10 -8
  72. data/lib/travis/cli/sshkey.rb +31 -27
  73. data/lib/travis/cli/status.rb +5 -3
  74. data/lib/travis/cli/sync.rb +9 -7
  75. data/lib/travis/cli/token.rb +4 -2
  76. data/lib/travis/cli/version.rb +4 -3
  77. data/lib/travis/cli/whatsup.rb +10 -8
  78. data/lib/travis/cli/whoami.rb +2 -2
  79. data/lib/travis/cli.rb +81 -76
  80. data/lib/travis/client/account.rb +8 -6
  81. data/lib/travis/client/artifact.rb +16 -12
  82. data/lib/travis/client/auto_login.rb +7 -4
  83. data/lib/travis/client/broadcast.rb +2 -0
  84. data/lib/travis/client/build.rb +7 -3
  85. data/lib/travis/client/cache.rb +4 -2
  86. data/lib/travis/client/commit.rb +5 -2
  87. data/lib/travis/client/entity.rb +50 -46
  88. data/lib/travis/client/env_var.rb +13 -8
  89. data/lib/travis/client/error.rb +5 -3
  90. data/lib/travis/client/has_uuid.rb +3 -1
  91. data/lib/travis/client/job.rb +8 -3
  92. data/lib/travis/client/lint_result.rb +2 -0
  93. data/lib/travis/client/listener.rb +70 -55
  94. data/lib/travis/client/methods.rb +26 -5
  95. data/lib/travis/client/namespace.rb +20 -16
  96. data/lib/travis/client/not_loadable.rb +3 -1
  97. data/lib/travis/client/repository.rb +34 -22
  98. data/lib/travis/client/request.rb +5 -2
  99. data/lib/travis/client/restartable.rb +2 -0
  100. data/lib/travis/client/session.rb +118 -88
  101. data/lib/travis/client/settings.rb +8 -3
  102. data/lib/travis/client/singleton_setting.rb +2 -0
  103. data/lib/travis/client/ssh_key.rb +2 -0
  104. data/lib/travis/client/states.rb +8 -6
  105. data/lib/travis/client/user.rb +2 -0
  106. data/lib/travis/client/weak_entity.rb +6 -3
  107. data/lib/travis/client.rb +4 -1
  108. data/lib/travis/pro/auto_login.rb +2 -0
  109. data/lib/travis/pro.rb +2 -0
  110. data/lib/travis/tools/assets.rb +6 -3
  111. data/lib/travis/tools/completion.rb +10 -6
  112. data/lib/travis/tools/formatter.rb +20 -14
  113. data/lib/travis/tools/github.rb +59 -49
  114. data/lib/travis/tools/notification.rb +18 -13
  115. data/lib/travis/tools/safe_string.rb +4 -1
  116. data/lib/travis/tools/ssl_key.rb +5 -2
  117. data/lib/travis/tools/system.rb +11 -6
  118. data/lib/travis/version.rb +3 -1
  119. data/lib/travis.rb +3 -1
  120. data/spec/cli/api_command_spec.rb +11 -8
  121. data/spec/cli/cancel_spec.rb +2 -4
  122. data/spec/cli/encrypt_file_spec.rb +9 -7
  123. data/spec/cli/encrypt_spec.rb +19 -17
  124. data/spec/cli/endpoint_spec.rb +12 -10
  125. data/spec/cli/help_spec.rb +14 -12
  126. data/spec/cli/history_spec.rb +2 -0
  127. data/spec/cli/init_spec.rb +35 -33
  128. data/spec/cli/logs_spec.rb +2 -0
  129. data/spec/cli/open_spec.rb +6 -4
  130. data/spec/cli/repo_command_spec.rb +8 -4
  131. data/spec/cli/restart_spec.rb +2 -4
  132. data/spec/cli/setup/service_spec.rb +17 -18
  133. data/spec/cli/setup_spec.rb +2 -4
  134. data/spec/cli/show_spec.rb +4 -2
  135. data/spec/cli/status_spec.rb +7 -5
  136. data/spec/cli/token_spec.rb +7 -5
  137. data/spec/cli/version_spec.rb +2 -0
  138. data/spec/cli/whoami_spec.rb +9 -7
  139. data/spec/client/account_spec.rb +28 -20
  140. data/spec/client/auto_login_spec.rb +12 -9
  141. data/spec/client/broadcast_spec.rb +5 -3
  142. data/spec/client/build_spec.rb +28 -24
  143. data/spec/client/commit_spec.rb +17 -14
  144. data/spec/client/job_spec.rb +27 -23
  145. data/spec/client/methods_spec.rb +8 -4
  146. data/spec/client/namespace_spec.rb +8 -4
  147. data/spec/client/repository_spec.rb +33 -30
  148. data/spec/client/session_spec.rb +71 -67
  149. data/spec/client/user_spec.rb +13 -10
  150. data/spec/client_spec.rb +6 -4
  151. data/spec/pro_spec.rb +5 -3
  152. data/spec/spec_helper.rb +3 -1
  153. data/spec/support/fake_api.rb +662 -662
  154. data/spec/support/fake_github.rb +6 -3
  155. data/spec/support/helpers.rb +13 -8
  156. data/spec/travis_spec.rb +5 -3
  157. data/travis.gemspec +402 -399
  158. metadata +31 -49
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
4
6
  module Client
5
7
  class Build < Entity
6
- include States, Restartable
8
+ include Restartable
9
+ include States
7
10
  preloadable
8
11
 
9
12
  # @!parse attr_reader :repository_id, :commit_id, :number, :pull_request, :pull_request_number, :pull_request_title, :config, :state, :started_at, :finished_at, :duration, :job_ids
10
- attributes :repository_id, :commit_id, :number, :pull_request, :pull_request_number, :pull_request_title, :config, :state, :started_at, :finished_at, :duration, :job_ids
13
+ attributes :repository_id, :commit_id, :number, :pull_request, :pull_request_number, :pull_request_title,
14
+ :config, :state, :started_at, :finished_at, :duration, :job_ids
11
15
  time :started_at, :finished_at
12
16
 
13
17
  alias pull_request? pull_request
@@ -27,7 +31,7 @@ module Travis
27
31
  end
28
32
 
29
33
  def push?
30
- not pull_request?
34
+ !pull_request?
31
35
  end
32
36
 
33
37
  def branch_info
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client/weak_entity'
2
4
 
3
5
  module Travis
@@ -14,11 +16,11 @@ module Travis
14
16
  many :caches
15
17
 
16
18
  def delete
17
- repository.delete_caches(:branch => branch, :match => slug)
19
+ repository.delete_caches(branch:, match: slug)
18
20
  end
19
21
 
20
22
  def inspect_info
21
- [repository.slug, branch, slug].compact.join(" ")
23
+ [repository.slug, branch, slug].compact.join(' ')
22
24
  end
23
25
  end
24
26
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -6,7 +8,8 @@ module Travis
6
8
  include NotLoadable
7
9
 
8
10
  # @!parse attr_reader :sha, :branch, :message, :committed_at, :author_name, :author_email, :committer_name, :committer_email, :compare_url
9
- attributes :sha, :branch, :message, :committed_at, :author_name, :author_email, :committer_name, :committer_email, :compare_url
11
+ attributes :sha, :branch, :message, :committed_at, :author_name, :author_email, :committer_name,
12
+ :committer_email, :compare_url
10
13
  time :committed_at
11
14
 
12
15
  one :commit
@@ -21,7 +24,7 @@ module Travis
21
24
  end
22
25
 
23
26
  def inspect_info
24
- short_sha + " " + subject.inspect
27
+ "#{short_sha} #{subject.inspect}"
25
28
  end
26
29
  end
27
30
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
  require 'time'
3
5
 
@@ -48,7 +50,7 @@ module Travis
48
50
 
49
51
  list.each do |name|
50
52
  name = name.to_s
51
- fail "can't call an attribute id" if name == "id"
53
+ raise "can't call an attribute id" if name == 'id'
52
54
 
53
55
  @attributes << name
54
56
  define_method(name) { load_attribute(name) }
@@ -111,6 +113,7 @@ module Travis
111
113
 
112
114
  def initialize(session, id)
113
115
  raise Travis::Client::Error, '%p is not a valid id' % id unless self.class.id? id
116
+
114
117
  @attributes = {}
115
118
  @session = session
116
119
  @id = self.class.cast_id(id) if id
@@ -155,6 +158,7 @@ module Travis
155
158
 
156
159
  def missing?(key)
157
160
  return false unless include? key
161
+
158
162
  !attributes.include?(key.to_s)
159
163
  end
160
164
 
@@ -164,7 +168,7 @@ module Travis
164
168
 
165
169
  def inspect
166
170
  klass = self.class
167
- klass = curry if curry and curry.name and curry.to_s.size < klass.to_s.size
171
+ klass = curry if curry&.name && curry.to_s.size < klass.to_s.size
168
172
  "#<#{klass}: #{inspect_info}>"
169
173
  end
170
174
 
@@ -182,57 +186,57 @@ module Travis
182
186
 
183
187
  private
184
188
 
185
- def relation(name)
186
- name = name.to_s
187
- entity = Entity.subclass_for(name)
188
-
189
- if entity.many == name
190
- Array(send("#{entity.one}_ids")).map do |id|
191
- session.find_one(entity, id)
192
- end
193
- else
194
- id = send("#{name}_id")
195
- session.find_one(entity, id) unless id.nil?
189
+ def relation(name)
190
+ name = name.to_s
191
+ entity = Entity.subclass_for(name)
192
+
193
+ if entity.many == name
194
+ Array(send("#{entity.one}_ids")).map do |id|
195
+ session.find_one(entity, id)
196
196
  end
197
+ else
198
+ id = send("#{name}_id")
199
+ session.find_one(entity, id) unless id.nil?
197
200
  end
201
+ end
198
202
 
199
- def inspect_info
200
- id
201
- end
203
+ def inspect_info
204
+ id
205
+ end
202
206
 
203
- def set_attribute(name, value)
204
- attributes[name.to_s] = value
205
- end
207
+ def set_attribute(name, value)
208
+ attributes[name.to_s] = value
209
+ end
206
210
 
207
- def load_attribute(name)
208
- session.reload(self) if missing? name
209
- attributes[name.to_s]
210
- end
211
+ def load_attribute(name)
212
+ session.reload(self) if missing? name
213
+ attributes[name.to_s]
214
+ end
211
215
 
212
- # shamelessly stolen from sinatra
213
- def time(value)
214
- if value.respond_to? :to_time
215
- value.to_time
216
- elsif value.is_a? Time
217
- value
218
- elsif value.respond_to? :new_offset
219
- d = value.new_offset 0
220
- t = Time.utc d.year, d.mon, d.mday, d.hour, d.min, d.sec + d.sec_fraction
221
- t.getlocal
222
- elsif value.respond_to? :mday
223
- Time.local(value.year, value.mon, value.mday)
224
- elsif value.is_a? Numeric
225
- Time.at value
226
- elsif value.nil? or value.empty?
227
- nil
228
- else
229
- Time.parse value.to_s
230
- end
231
- rescue ArgumentError => boom
232
- raise boom
233
- rescue Exception
234
- raise ArgumentError, "unable to convert #{value.inspect} to a Time object"
216
+ # shamelessly stolen from sinatra
217
+ def time(value)
218
+ if value.respond_to? :to_time
219
+ value.to_time
220
+ elsif value.is_a? Time
221
+ value
222
+ elsif value.respond_to? :new_offset
223
+ d = value.new_offset 0
224
+ t = Time.utc d.year, d.mon, d.mday, d.hour, d.min, d.sec + d.sec_fraction
225
+ t.getlocal
226
+ elsif value.respond_to? :mday
227
+ Time.local(value.year, value.mon, value.mday)
228
+ elsif value.is_a? Numeric
229
+ Time.at value
230
+ elsif value.nil? || value.empty?
231
+ nil
232
+ else
233
+ Time.parse value.to_s
235
234
  end
235
+ rescue ArgumentError => e
236
+ raise e
237
+ rescue Exception
238
+ raise ArgumentError, "unable to convert #{value.inspect} to a Time object"
239
+ end
236
240
  end
237
241
  end
238
242
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
  require 'delegate'
3
5
 
@@ -35,7 +37,7 @@ module Travis
35
37
  end
36
38
 
37
39
  def add(name, value, options = {})
38
- body = JSON.dump(:env_var => options.merge(:name => name, :value => value))
40
+ body = JSON.dump(env_var: options.merge(name:, value:))
39
41
  result = session.post(EnvVar.path(self), body)
40
42
  self.list += [result['env_var']]
41
43
  end
@@ -43,8 +45,8 @@ module Travis
43
45
  def upsert(name, value, options = {})
44
46
  entries = select { |e| e.name == name }
45
47
  if entries.any?
46
- entries.first.update(options.merge(:value => value))
47
- entries[1..-1].each { |e| e.delete }
48
+ entries.first.update(options.merge(value:))
49
+ entries[1..].each { |e| e.delete }
48
50
  else
49
51
  add(name, value, options)
50
52
  end
@@ -53,11 +55,13 @@ module Travis
53
55
 
54
56
  def [](key)
55
57
  return super if key.is_a? Integer
58
+
56
59
  detect { |e| e.name == key.to_s }
57
60
  end
58
61
 
59
62
  def []=(key, value)
60
63
  return super if key.is_a? Integer
64
+
61
65
  upsert(key.to_s, value)
62
66
  end
63
67
 
@@ -65,8 +69,9 @@ module Travis
65
69
  end
66
70
 
67
71
  def self.path(object)
68
- repository_id = Repository === object ? object.id : object.repository_id
69
- raise "repository unknown" unless repository_id
72
+ repository_id = object.is_a?(Repository) ? object.id : object.repository_id
73
+ raise 'repository unknown' unless repository_id
74
+
70
75
  "/settings/env_vars/#{object.id if object.is_a? EnvVar}?repository_id=#{repository_id}"
71
76
  end
72
77
 
@@ -82,8 +87,8 @@ module Travis
82
87
  has :repository
83
88
 
84
89
  def update(options)
85
- options = { :value => options } unless options.is_a? Hash
86
- result = session.patch(EnvVar.path(self), JSON.dump(:env_var => options))
90
+ options = { value: options } unless options.is_a? Hash
91
+ result = session.patch(EnvVar.path(self), JSON.dump(env_var: options))
87
92
  attributes.replace(result['env_var'].attributes)
88
93
  self
89
94
  end
@@ -95,7 +100,7 @@ module Travis
95
100
  end
96
101
 
97
102
  def inspect_info
98
- "#{name}=#{value ? value.inspect : "[secure]"}"
103
+ "#{name}=#{value ? value.inspect : '[secure]'}"
99
104
  end
100
105
  end
101
106
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -25,7 +27,7 @@ module Travis
25
27
 
26
28
  class AssetNotFound < Error
27
29
  def initialize(file, *args)
28
- if md = file.match(%r[init/(?<lang>[^\.]+)\.yml$])
30
+ if (md = file.match(%r{init/(?<lang>[^.]+)\.yml$}))
29
31
  super "unknown language #{md[:lang]}", *args
30
32
  else
31
33
  super file, *args
@@ -42,9 +44,9 @@ module Travis
42
44
  end
43
45
 
44
46
  def parse_message(message)
45
- response = JSON.load(message)
47
+ response = JSON.parse(message)
46
48
  message = response['message'].to_s
47
- if @errors = response['errors'] and @errors.any?
49
+ if (@errors = response['errors']) && @errors.any?
48
50
  readable = @errors.map { |e| "#{e['field']}: #{e['code'].gsub('_', ' ')}" }
49
51
  message += " (#{readable.join(', ')})"
50
52
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  module Client
3
5
  module HasUuid
4
6
  def id?(object)
5
- object =~ /\A(?:\w+-){4}\w+\Z/ if object.is_a? String
7
+ object =~ /\A(?:\w+-){4}\w+\Z/ if object.is_a? String
6
8
  end
7
9
 
8
10
  def cast_id(object)
@@ -1,13 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
4
6
  module Client
5
7
  class Job < Entity
6
- include States, Restartable
8
+ include Restartable
9
+ include States
7
10
  preloadable
8
11
 
9
12
  # @!parse attr_reader :repository_id, :build_id, :commit_id, :log_id, :number, :config, :state, :started_at, :finished_at, :queue, :allow_failure, :tags
10
- attributes :repository_id, :build_id, :commit_id, :log_id, :number, :config, :state, :started_at, :finished_at, :queue, :allow_failure, :tags
13
+ attributes :repository_id, :build_id, :commit_id, :log_id, :number, :config, :state, :started_at, :finished_at,
14
+ :queue, :allow_failure, :tags
11
15
  time :started_at, :finished_at
12
16
 
13
17
  alias allow_failure? allow_failure
@@ -31,7 +35,8 @@ module Travis
31
35
  end
32
36
 
33
37
  def allow_failures?
34
- return false unless config.include? 'matrix' and config['matrix'].include? 'allow_failures'
38
+ return false unless config.include?('matrix') && config['matrix'].include?('allow_failures')
39
+
35
40
  config['matrix']['allow_failures'].any? do |allow|
36
41
  allow.all? { |key, value| config[key] == value }
37
42
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  module Client
3
5
  class LintResult
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
  require 'forwardable'
3
5
  require 'json'
@@ -13,6 +15,7 @@ module Travis
13
15
  class Listener
14
16
  class Socket < PusherClient::Socket
15
17
  attr_accessor :session, :signatures
18
+
16
19
  def initialize(application_key, options = {})
17
20
  @session = options.fetch(:session)
18
21
  @signatures = {}
@@ -31,7 +34,10 @@ module Travis
31
34
 
32
35
  def fetch_auth(*channels)
33
36
  channels.select! { |c| signatures[c].nil? if c.start_with? 'private-' }
34
- signatures.merge! session.post_raw('/pusher/auth', :channels => channels, :socket_id => socket_id)['channels'] if channels.any?
37
+ return unless channels.any?
38
+
39
+ signatures.merge! session.post_raw('/pusher/auth', channels:,
40
+ socket_id:)['channels']
35
41
  end
36
42
 
37
43
  def get_private_auth(channel)
@@ -40,19 +46,22 @@ module Travis
40
46
  end
41
47
 
42
48
  def handle_error(data)
43
- code, message = data["code"], data["message"] if data.is_a? Hash
49
+ if data.is_a? Hash
50
+ code = data['code']
51
+ message = data['message']
52
+ end
44
53
  message ||= data.inspect
45
54
 
46
55
  case code
47
56
  when 4100 then reconnect(1)
48
57
  when 4200, 4201, 4202 then reconnect
49
- else raise Travis::Client::Error, "Pusher error: %s (code: %p)" % [message, code]
58
+ else raise Travis::Client::Error, format('Pusher error: %s (code: %p)', message, code)
50
59
  end
51
60
  end
52
61
 
53
62
  def reconnect(delay = nil)
54
63
  disconnect if connected
55
- sleep delay if delay and delay > 0
64
+ sleep delay if delay&.positive?
56
65
  connect
57
66
  end
58
67
  end
@@ -60,7 +69,7 @@ module Travis
60
69
  EVENTS = %w[
61
70
  build:created build:started build:finished
62
71
  job:created job:started job:log job:finished
63
- ]
72
+ ].freeze
64
73
 
65
74
  Event = Struct.new(:type, :repository, :build, :job, :payload)
66
75
 
@@ -71,7 +80,8 @@ module Travis
71
80
  def_delegators :listener, :disconnect, :on_connect, :subscribe
72
81
 
73
82
  def initialize(listener, entities)
74
- @listener, @entities = listener, Array(entities)
83
+ @listener = listener
84
+ @entities = Array(entities)
75
85
  end
76
86
 
77
87
  def on(*events)
@@ -80,11 +90,11 @@ module Travis
80
90
 
81
91
  private
82
92
 
83
- def dispatch?(event)
84
- entities.include? event.repository or
85
- entities.include? event.build or
93
+ def dispatch?(event)
94
+ entities.include? event.repository or
95
+ entities.include? event.build or
86
96
  entities.include? event.job
87
- end
97
+ end
88
98
  end
89
99
 
90
100
  attr_reader :session, :socket
@@ -111,15 +121,15 @@ module Travis
111
121
  events.each { |e| @callbacks << [e, block] }
112
122
  end
113
123
 
114
- def on_connect
115
- socket.bind('pusher:connection_established') { yield }
124
+ def on_connect(&block)
125
+ socket.bind('pusher:connection_established', &block)
116
126
  end
117
127
 
118
128
  def listen
119
129
  @channels = default_channels if @channels.empty?
120
130
  @channels.map! { |c| c.start_with?('private-') ? c : "private-#{c}" } if session.private_channels?
121
131
  @channels.uniq.each { |c| socket.subscribe(c) }
122
- @callbacks.each { |e,b| socket.bind(e) { |d| dispatch(e, d, &b) } }
132
+ @callbacks.each { |e, b| socket.bind(e) { |d| dispatch(e, d, &b) } }
123
133
  socket.connect
124
134
  end
125
135
 
@@ -129,55 +139,60 @@ module Travis
129
139
 
130
140
  private
131
141
 
132
- def dispatch(type, json)
133
- payload = JSON.parse(json)
134
- entities = session.load format_payload(type, payload)
135
- yield Event.new(type, entities['repository'], entities['build'], entities['job'], payload)
136
- end
142
+ def dispatch(type, json)
143
+ payload = JSON.parse(json)
144
+ entities = session.load format_payload(type, payload)
145
+ yield Event.new(type, entities['repository'], entities['build'], entities['job'], payload)
146
+ end
137
147
 
138
- def format_payload(type, payload)
139
- case type
140
- when "job:log" then format_log(payload)
141
- when /job:/ then format_job(payload)
142
- else payload
143
- end
148
+ def format_payload(type, payload)
149
+ case type
150
+ when 'job:log' then format_log(payload)
151
+ when /job:/ then format_job(payload)
152
+ else payload
144
153
  end
154
+ end
145
155
 
146
- def format_job(payload)
147
- build = { "id" => payload["build_id"], "repository_id" => payload["repository_id"] }
148
- repo = { "id" => payload["repository_id"], "slug" => payload["repository_slug"] }
149
- build["number"] = payload["number"][/^[^\.]+/] if payload["number"]
150
- { "job" => payload, "build" => build, "repository" => repo }
151
- end
156
+ def format_job(payload)
157
+ build = { 'id' => payload['build_id'], 'repository_id' => payload['repository_id'] }
158
+ repo = { 'id' => payload['repository_id'], 'slug' => payload['repository_slug'] }
159
+ build['number'] = payload['number'][/^[^.]+/] if payload['number']
160
+ { 'job' => payload, 'build' => build, 'repository' => repo }
161
+ end
152
162
 
153
- def format_log(payload)
154
- job = session.job(payload['id'])
155
- { "job" => { "id" => job.id }, "build" => { "id" => job.build.id }, "repository" => { "id" => job.repository.id } }
156
- end
163
+ def format_log(payload)
164
+ job = session.job(payload['id'])
165
+ { 'job' => { 'id' => job.id }, 'build' => { 'id' => job.build.id },
166
+ 'repository' => { 'id' => job.repository.id } }
167
+ end
157
168
 
158
- def default_channels
159
- return ['common'] if session.access_token.nil?
160
- session.user.channels
161
- end
169
+ def default_channels
170
+ return ['common'] if session.access_token.nil?
162
171
 
163
- def pusher_options
164
- pusher_options = session.config['pusher'] || {}
165
- encrypted = pusher_options['scheme'] != 'http'
166
- options = { :encrypted => encrypted, :session => session }
167
- options[:ws_host] = pusher_options['host'] if pusher_options['host']
168
- options[:wss_port] = pusher_options['port'] if encrypted and pusher_options['port']
169
- options[:ws_port] = pusher_options['port'] if !encrypted and pusher_options['port']
170
- options[:ws_path] = pusher_options['path'] if pusher_options['path']
171
- options[:ws_path] = '/' << options[:ws_path] unless options[:ws_path].nil? or options[:ws_path].start_with? '/'
172
- options[:ssl_verify] = session.ssl.fetch(:verify, true)
173
- options
174
- end
172
+ session.user.channels
173
+ end
175
174
 
176
- def pusher_key
177
- session.config.fetch('pusher').fetch('key')
178
- rescue IndexError
179
- raise Travis::Client::Error, "#{session.api_endpoint} is missing pusher key"
180
- end
175
+ def pusher_options
176
+ pusher_options = session.config['pusher'] || {}
177
+ encrypted = pusher_options['scheme'] != 'http'
178
+ options = { encrypted:, session: }
179
+ options[:ws_host] = pusher_options['host'] if pusher_options['host']
180
+ options[:wss_port] = pusher_options['port'] if encrypted && pusher_options['port']
181
+ options[:ws_port] = pusher_options['port'] if !encrypted && pusher_options['port']
182
+ options[:ws_path] = pusher_options['path'] if pusher_options['path']
183
+ unless options[:ws_path].nil? || options[:ws_path].start_with?('/')
184
+ options[:ws_path] =
185
+ '/' << options[:ws_path]
186
+ end
187
+ options[:ssl_verify] = session.ssl.fetch(:verify, true)
188
+ options
189
+ end
190
+
191
+ def pusher_key
192
+ session.config.fetch('pusher').fetch('key')
193
+ rescue IndexError
194
+ raise Travis::Client::Error, "#{session.api_endpoint} is missing pusher key"
195
+ end
181
196
  end
182
197
  end
183
198
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
  require 'yaml'
3
5
 
@@ -17,12 +19,13 @@ module Travis
17
19
  end
18
20
 
19
21
  def github_auth(github_token)
20
- reply = session.post_raw("/auth/github", :github_token => github_token)
21
- unless reply.respond_to?(:key?) && reply.key?("access_token")
22
- raise InvalidTokenError, 'token is invalid, or does not have sufficient scope; see https://docs.travis-ci.com/user/github-oauth-scopes/ for more information on scope'
22
+ reply = session.post_raw('/auth/github', github_token:)
23
+ unless reply.respond_to?(:key?) && reply.key?('access_token')
24
+ raise InvalidTokenError,
25
+ 'token is invalid, or does not have sufficient scope; see https://docs.travis-ci.com/user/github-oauth-scopes/ for more information on scope'
23
26
  end
24
27
 
25
- session.access_token = reply["access_token"]
28
+ session.access_token = reply['access_token']
26
29
  end
27
30
 
28
31
  def explicit_api_endpoint?
@@ -67,7 +70,7 @@ module Travis
67
70
  end
68
71
 
69
72
  def accounts
70
- session.find_many(Account, :all => true)
73
+ session.find_many(Account, all: true)
71
74
  end
72
75
 
73
76
  def broadcasts
@@ -78,12 +81,14 @@ module Travis
78
81
  # btw, internally we call this reset, not restart, as it resets the state machine
79
82
  # but we thought that would be too confusing
80
83
  raise Error, "cannot restart a #{entity.class.one}" unless entity.restartable?
84
+
81
85
  session.post_raw("/#{entity.class.many}/#{entity.id}/restart")
82
86
  entity.reload
83
87
  end
84
88
 
85
89
  def cancel(entity)
86
90
  raise Error, "cannot cancel a #{entity.class.one}" unless entity.cancelable?
91
+
87
92
  session.post_raw("/#{entity.class.many}/#{entity.id}/cancel")
88
93
  entity.reload
89
94
  end
@@ -92,6 +97,22 @@ module Travis
92
97
  session.get_raw('/logout')
93
98
  end
94
99
 
100
+ def regenerate_token
101
+ session.headers['Travis-Api-Version'] = '3'
102
+ token = session.patch_raw('/access_token')
103
+ session.headers.delete('Travis-Api-Version')
104
+
105
+ token
106
+ end
107
+
108
+ def remove_token
109
+ session.headers['Travis-Api-Version'] = '3'
110
+ resp = session.delete_raw('/access_token')
111
+ session.headers.delete('Travis-Api-Version')
112
+
113
+ resp
114
+ end
115
+
95
116
  def listen(*entities, &block)
96
117
  listener = Listener.new(session)
97
118
  listener.subscribe(*entities, &block)