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
@@ -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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis
@@ -7,7 +9,8 @@ module Travis
7
9
  attr_accessor :namespace, :type
8
10
 
9
11
  def initialize(namespace, type)
10
- @namespace, @type = namespace, type
12
+ @namespace = namespace
13
+ @type = type
11
14
  end
12
15
 
13
16
  def find_one(id = nil)
@@ -41,9 +44,9 @@ module Travis
41
44
 
42
45
  private
43
46
 
44
- def session
45
- namespace.session
46
- end
47
+ def session
48
+ namespace.session
49
+ end
47
50
  end
48
51
 
49
52
  include Methods
@@ -66,20 +69,21 @@ module Travis
66
69
 
67
70
  private
68
71
 
69
- def fix_names(klass)
70
- constants.each do |name|
71
- const = klass.const_get(name)
72
- klass.const_set(name, const) if const == const_get(name)
73
- end
72
+ def fix_names(klass)
73
+ constants.each do |name|
74
+ const = klass.const_get(name)
75
+ klass.const_set(name, const) if const == const_get(name)
74
76
  end
77
+ end
75
78
 
76
- def delegate_session(klass)
77
- return if klass == Object or klass == Kernel
78
- klass.extend(Methods)
79
- namespace = self
80
- klass.define_singleton_method(:session) { namespace.session }
81
- klass.define_singleton_method(:session=) { |value| namespace.session = value }
82
- end
79
+ def delegate_session(klass)
80
+ return if [Object, Kernel].include?(klass)
81
+
82
+ klass.extend(Methods)
83
+ namespace = self
84
+ klass.define_singleton_method(:session) { namespace.session }
85
+ klass.define_singleton_method(:session=) { |value| namespace.session = value }
86
+ end
83
87
  end
84
88
  end
85
89
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Travis
2
4
  module Client
3
5
  module NotLoadable
4
- def missing?(attribute)
6
+ def missing?(_attribute)
5
7
  false
6
8
  end
7
9
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
  require 'travis/tools/ssl_key'
3
5
 
@@ -14,7 +16,7 @@ module Travis
14
16
 
15
17
  def encrypt(value)
16
18
  encrypted = to_rsa.public_encrypt(value)
17
- Base64.encode64(encrypted).gsub(/\s+/, "")
19
+ Base64.encode64(encrypted).gsub(/\s+/, '')
18
20
  end
19
21
 
20
22
  def to_rsa
@@ -34,7 +36,8 @@ module Travis
34
36
  preloadable
35
37
 
36
38
  # @!parse attr_reader :slug, :description
37
- attributes :slug, :active, :private, :admin, :description, :last_build_id, :last_build_number, :last_build_state, :last_build_duration, :last_build_started_at, :last_build_finished_at, :github_language
39
+ attributes :slug, :active, :private, :admin, :description, :last_build_id, :last_build_number, :last_build_state,
40
+ :last_build_duration, :last_build_started_at, :last_build_finished_at, :github_language
38
41
  inspect_info :slug
39
42
 
40
43
  time :last_build_finished_at, :last_build_started_at
@@ -51,14 +54,14 @@ module Travis
51
54
  end
52
55
 
53
56
  def public_key
54
- attributes["public_key"] ||= begin
57
+ attributes['public_key'] ||= begin
55
58
  payload = session.get_raw("/repos/#{id}/key")
56
59
  Key.new(payload.fetch('key'), payload['fingerprint'])
57
60
  end
58
61
  end
59
62
 
60
63
  def name
61
- slug[/[^\/]+$/]
64
+ slug[%r{[^/]+$}]
62
65
  end
63
66
 
64
67
  def public_key=(key)
@@ -75,6 +78,7 @@ module Travis
75
78
  # @!parse attr_reader :last_build
76
79
  def last_build
77
80
  return unless last_build_id
81
+
78
82
  attributes['last_build'] ||= begin
79
83
  last_build = session.find_one(Build, last_build_id)
80
84
  last_build.number = last_build_number
@@ -89,11 +93,12 @@ module Travis
89
93
 
90
94
  def builds(params = nil)
91
95
  return each_build unless params
92
- session.find_many(Build, params.merge(:repository_id => id))
96
+
97
+ session.find_many(Build, params.merge(repository_id: id))
93
98
  end
94
99
 
95
100
  def build(number)
96
- builds(:number => number.to_s).first
101
+ builds(number: number.to_s).first
97
102
  end
98
103
 
99
104
  def recent_builds
@@ -102,7 +107,8 @@ module Travis
102
107
 
103
108
  def last_on_branch(name = nil)
104
109
  return branch(name) if name
105
- attributes['last_on_branch'] ||= session.get('branches', :repository_id => id)['branches']
110
+
111
+ attributes['last_on_branch'] ||= session.get('branches', repository_id: id)['branches']
106
112
  end
107
113
 
108
114
  def branches
@@ -112,19 +118,24 @@ module Travis
112
118
  def branch(name)
113
119
  attributes['branches'] ||= {}
114
120
  attributes['branches'][name] ||= begin
115
- build = attributes['last_on_branch'].detect { |b| b.commit.branch == name.to_s } if attributes['last_on_branch']
121
+ if attributes['last_on_branch']
122
+ build = attributes['last_on_branch'].detect do |b|
123
+ b.commit.branch == name.to_s
124
+ end
125
+ end
116
126
  build || session.get("/repos/#{id}/branches/#{name}")['branch']
117
127
  end
118
128
  end
119
129
 
120
130
  def each_build(params = nil, &block)
121
131
  return enum_for(__method__, params) unless block_given?
132
+
122
133
  params ||= {}
123
134
  chunk = builds(params)
124
135
  until chunk.empty?
125
136
  chunk.each(&block)
126
137
  number = chunk.last.number
127
- chunk = number == '1' ? [] : builds(params.merge(:after_number => number))
138
+ chunk = number == '1' ? [] : builds(params.merge(after_number: number))
128
139
  end
129
140
  self
130
141
  end
@@ -133,12 +144,12 @@ module Travis
133
144
  build_number = number.to_s[/^\d+/] or return nil
134
145
  build = build(build_number) or return nil
135
146
  job = build.jobs.detect { |j| j.number == number } if number != build_number
136
- job ||= build.jobs.first if build and build.jobs.size == 1
147
+ job ||= build.jobs.first if build && (build.jobs.size == 1)
137
148
  job
138
149
  end
139
150
 
140
151
  def set_hook(flag)
141
- result = session.put_raw('/hooks/', :hook => { :id => id, :active => flag })
152
+ result = session.put_raw('/hooks/', hook: { id:, active: flag })
142
153
  result['result']
143
154
  end
144
155
 
@@ -152,10 +163,10 @@ module Travis
152
163
 
153
164
  def pusher_channels
154
165
  attributes['pusher_channels'] ||= if session.private_channels?
155
- ["user-#{session.user.id}", "repo-#{id}"]
156
- else
157
- ["common"]
158
- end
166
+ ["user-#{session.user.id}", "repo-#{id}"]
167
+ else
168
+ ['common']
169
+ end
159
170
  end
160
171
 
161
172
  def member?
@@ -163,7 +174,7 @@ module Travis
163
174
  end
164
175
 
165
176
  def owner_name
166
- slug[/^[^\/]+/]
177
+ slug[%r{^[^/]+}]
167
178
  end
168
179
 
169
180
  def owner
@@ -171,7 +182,7 @@ module Travis
171
182
  end
172
183
 
173
184
  def requests
174
- attributes['requests'] ||= session.find_many(Request, :repository_id => id)
185
+ attributes['requests'] ||= session.find_many(Request, repository_id: id)
175
186
  end
176
187
 
177
188
  def settings
@@ -181,7 +192,7 @@ module Travis
181
192
  settings
182
193
  end
183
194
  rescue Travis::Client::NotFound
184
- raise Travis::Client::Error, "not allowed to access settings"
195
+ raise Travis::Client::Error, 'not allowed to access settings'
185
196
  end
186
197
 
187
198
  def caches(params = {})
@@ -193,8 +204,9 @@ module Travis
193
204
  end
194
205
 
195
206
  def active?
196
- # TODO remove once active is properly synced and exposed by api
207
+ # TODO: remove once active is properly synced and exposed by api
197
208
  return active unless active.nil?
209
+
198
210
  last_build_id?
199
211
  end
200
212
 
@@ -216,9 +228,9 @@ module Travis
216
228
 
217
229
  private
218
230
 
219
- def state
220
- last_build_state
221
- end
231
+ def state
232
+ last_build_state
233
+ end
222
234
  end
223
235
  end
224
236
  end
@@ -1,10 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client/weak_entity'
2
4
 
3
5
  module Travis
4
6
  module Client
5
7
  class Request < WeakEntity
6
8
  # @!parse attr_reader :commit_id, :repository_id, :created_at, :owner_id, :owner_type, :event_type, :base_commit, :head_commit, :result, :message, :pull_request, :pull_request_number, :pull_request_title, :branch, :tag
7
- attributes :commit_id, :repository_id, :created_at, :owner_id, :owner_type, :event_type, :base_commit, :head_commit, :result, :message, :pull_request, :pull_request_number, :pull_request_title, :branch, :tag
9
+ attributes :commit_id, :repository_id, :created_at, :owner_id, :owner_type, :event_type, :base_commit,
10
+ :head_commit, :result, :message, :pull_request, :pull_request_number, :pull_request_title, :branch, :tag
8
11
  time :created_at
9
12
 
10
13
  # @!parse attr_reader :repository
@@ -29,7 +32,7 @@ module Travis
29
32
  [
30
33
  repository && repository.slug,
31
34
  event_type, branch || pull_request_number, result
32
- ].compact.join(" ")
35
+ ].compact.join(' ')
33
36
  end
34
37
  end
35
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'travis/client'
2
4
 
3
5
  module Travis