travis-akerl 1.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +2512 -0
  4. data/Rakefile +64 -0
  5. data/assets/cacert.pem +69 -0
  6. data/assets/init/c.yml +4 -0
  7. data/assets/init/clojure.yml +1 -0
  8. data/assets/init/cpp.yml +4 -0
  9. data/assets/init/erlang.yml +3 -0
  10. data/assets/init/go.yml +4 -0
  11. data/assets/init/groovy.yml +1 -0
  12. data/assets/init/haskell.yml +1 -0
  13. data/assets/init/java.yml +4 -0
  14. data/assets/init/node_js.yml +5 -0
  15. data/assets/init/objective-c.yml +1 -0
  16. data/assets/init/perl.yml +4 -0
  17. data/assets/init/php.yml +4 -0
  18. data/assets/init/python.yml +5 -0
  19. data/assets/init/ruby.yml +6 -0
  20. data/assets/init/scala.yml +4 -0
  21. data/assets/notifications/Travis CI.app/Contents/Info.plist +52 -0
  22. data/assets/notifications/Travis CI.app/Contents/MacOS/Travis CI +0 -0
  23. data/assets/notifications/Travis CI.app/Contents/PkgInfo +1 -0
  24. data/assets/notifications/Travis CI.app/Contents/Resources/Travis CI.icns +0 -0
  25. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
  26. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
  27. data/assets/notifications/Travis CI.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
  28. data/assets/notifications/Travis CI.app/Contents/_CodeSignature/CodeResources +173 -0
  29. data/assets/notifications/Travis CI.app/Contents/embedded.provisionprofile +0 -0
  30. data/assets/notifications/icon.png +0 -0
  31. data/assets/travis.sh +163 -0
  32. data/assets/travis.sh.erb +64 -0
  33. data/bin/travis +18 -0
  34. data/examples/org_overview.rb +3 -0
  35. data/examples/pro_auth.rb +23 -0
  36. data/examples/stream.rb +6 -0
  37. data/lib/travis/auto_login.rb +3 -0
  38. data/lib/travis/cli/accounts.rb +31 -0
  39. data/lib/travis/cli/api_command.rb +182 -0
  40. data/lib/travis/cli/branches.rb +25 -0
  41. data/lib/travis/cli/cache.rb +76 -0
  42. data/lib/travis/cli/cancel.rb +18 -0
  43. data/lib/travis/cli/command.rb +422 -0
  44. data/lib/travis/cli/console.rb +33 -0
  45. data/lib/travis/cli/disable.rb +15 -0
  46. data/lib/travis/cli/enable.rb +31 -0
  47. data/lib/travis/cli/encrypt.rb +115 -0
  48. data/lib/travis/cli/encrypt_file.rb +140 -0
  49. data/lib/travis/cli/endpoint.rb +35 -0
  50. data/lib/travis/cli/env.rb +66 -0
  51. data/lib/travis/cli/help.rb +23 -0
  52. data/lib/travis/cli/history.rb +49 -0
  53. data/lib/travis/cli/init.rb +82 -0
  54. data/lib/travis/cli/lint.rb +49 -0
  55. data/lib/travis/cli/login.rb +76 -0
  56. data/lib/travis/cli/logout.rb +14 -0
  57. data/lib/travis/cli/logs.rb +65 -0
  58. data/lib/travis/cli/monitor.rb +111 -0
  59. data/lib/travis/cli/open.rb +39 -0
  60. data/lib/travis/cli/parser.rb +43 -0
  61. data/lib/travis/cli/pubkey.rb +30 -0
  62. data/lib/travis/cli/raw.rb +20 -0
  63. data/lib/travis/cli/repo_command.rb +154 -0
  64. data/lib/travis/cli/report.rb +101 -0
  65. data/lib/travis/cli/repos.rb +53 -0
  66. data/lib/travis/cli/requests.rb +47 -0
  67. data/lib/travis/cli/restart.rb +18 -0
  68. data/lib/travis/cli/settings.rb +79 -0
  69. data/lib/travis/cli/setup/anynines.rb +21 -0
  70. data/lib/travis/cli/setup/appfog.rb +19 -0
  71. data/lib/travis/cli/setup/artifacts.rb +23 -0
  72. data/lib/travis/cli/setup/biicode.rb +19 -0
  73. data/lib/travis/cli/setup/cloud_66.rb +20 -0
  74. data/lib/travis/cli/setup/cloud_control.rb +21 -0
  75. data/lib/travis/cli/setup/cloud_files.rb +20 -0
  76. data/lib/travis/cli/setup/cloud_foundry.rb +23 -0
  77. data/lib/travis/cli/setup/code_deploy.rb +55 -0
  78. data/lib/travis/cli/setup/deis.rb +20 -0
  79. data/lib/travis/cli/setup/divshot.rb +18 -0
  80. data/lib/travis/cli/setup/elastic_beanstalk.rb +23 -0
  81. data/lib/travis/cli/setup/engine_yard.rb +24 -0
  82. data/lib/travis/cli/setup/gcs.rb +22 -0
  83. data/lib/travis/cli/setup/hackage.rb +18 -0
  84. data/lib/travis/cli/setup/heroku.rb +20 -0
  85. data/lib/travis/cli/setup/modulus.rb +18 -0
  86. data/lib/travis/cli/setup/ninefold.rb +20 -0
  87. data/lib/travis/cli/setup/nodejitsu.rb +27 -0
  88. data/lib/travis/cli/setup/npm.rb +20 -0
  89. data/lib/travis/cli/setup/open_shift.rb +20 -0
  90. data/lib/travis/cli/setup/opsworks.rb +22 -0
  91. data/lib/travis/cli/setup/pypi.rb +22 -0
  92. data/lib/travis/cli/setup/releases.rb +35 -0
  93. data/lib/travis/cli/setup/ruby_gems.rb +25 -0
  94. data/lib/travis/cli/setup/s3.rb +25 -0
  95. data/lib/travis/cli/setup/sauce_connect.rb +21 -0
  96. data/lib/travis/cli/setup/service.rb +73 -0
  97. data/lib/travis/cli/setup.rb +66 -0
  98. data/lib/travis/cli/show.rb +57 -0
  99. data/lib/travis/cli/sshkey.rb +118 -0
  100. data/lib/travis/cli/status.rb +19 -0
  101. data/lib/travis/cli/sync.rb +30 -0
  102. data/lib/travis/cli/token.rb +14 -0
  103. data/lib/travis/cli/version.rb +17 -0
  104. data/lib/travis/cli/whatsup.rb +30 -0
  105. data/lib/travis/cli/whoami.rb +15 -0
  106. data/lib/travis/cli.rb +126 -0
  107. data/lib/travis/client/account.rb +56 -0
  108. data/lib/travis/client/artifact.rb +88 -0
  109. data/lib/travis/client/auto_login.rb +45 -0
  110. data/lib/travis/client/broadcast.rb +14 -0
  111. data/lib/travis/client/build.rb +47 -0
  112. data/lib/travis/client/cache.rb +25 -0
  113. data/lib/travis/client/commit.rb +28 -0
  114. data/lib/travis/client/entity.rb +238 -0
  115. data/lib/travis/client/env_var.rb +102 -0
  116. data/lib/travis/client/error.rb +38 -0
  117. data/lib/travis/client/has_uuid.rb +13 -0
  118. data/lib/travis/client/job.rb +61 -0
  119. data/lib/travis/client/lint_result.rb +25 -0
  120. data/lib/travis/client/listener.rb +183 -0
  121. data/lib/travis/client/methods.rb +104 -0
  122. data/lib/travis/client/namespace.rb +85 -0
  123. data/lib/travis/client/not_loadable.rb +13 -0
  124. data/lib/travis/client/repository.rb +224 -0
  125. data/lib/travis/client/request.rb +36 -0
  126. data/lib/travis/client/restartable.rb +23 -0
  127. data/lib/travis/client/session.rb +339 -0
  128. data/lib/travis/client/settings.rb +25 -0
  129. data/lib/travis/client/singleton_setting.rb +36 -0
  130. data/lib/travis/client/ssh_key.rb +11 -0
  131. data/lib/travis/client/states.rb +98 -0
  132. data/lib/travis/client/user.rb +67 -0
  133. data/lib/travis/client/weak_entity.rb +26 -0
  134. data/lib/travis/client.rb +38 -0
  135. data/lib/travis/pro/auto_login.rb +3 -0
  136. data/lib/travis/pro.rb +5 -0
  137. data/lib/travis/tools/assets.rb +21 -0
  138. data/lib/travis/tools/completion.rb +54 -0
  139. data/lib/travis/tools/formatter.rb +50 -0
  140. data/lib/travis/tools/github.rb +293 -0
  141. data/lib/travis/tools/notification.rb +69 -0
  142. data/lib/travis/tools/safe_string.rb +22 -0
  143. data/lib/travis/tools/ssl_key.rb +48 -0
  144. data/lib/travis/tools/system.rb +88 -0
  145. data/lib/travis/version.rb +3 -0
  146. data/lib/travis.rb +8 -0
  147. data/spec/cli/api_command_spec.rb +38 -0
  148. data/spec/cli/cancel_spec.rb +15 -0
  149. data/spec/cli/encrypt_spec.rb +49 -0
  150. data/spec/cli/endpoint_spec.rb +39 -0
  151. data/spec/cli/help_spec.rb +33 -0
  152. data/spec/cli/history_spec.rb +38 -0
  153. data/spec/cli/init_spec.rb +227 -0
  154. data/spec/cli/login_spec.rb +13 -0
  155. data/spec/cli/logs_spec.rb +8 -0
  156. data/spec/cli/open_spec.rb +33 -0
  157. data/spec/cli/repo_command_spec.rb +25 -0
  158. data/spec/cli/restart_spec.rb +15 -0
  159. data/spec/cli/setup_spec.rb +5 -0
  160. data/spec/cli/show_spec.rb +9 -0
  161. data/spec/cli/status_spec.rb +28 -0
  162. data/spec/cli/token_spec.rb +22 -0
  163. data/spec/cli/version_spec.rb +18 -0
  164. data/spec/cli/whoami_spec.rb +34 -0
  165. data/spec/client/account_spec.rb +32 -0
  166. data/spec/client/auto_login_spec.rb +25 -0
  167. data/spec/client/broadcast_spec.rb +10 -0
  168. data/spec/client/build_spec.rb +31 -0
  169. data/spec/client/commit_spec.rb +22 -0
  170. data/spec/client/job_spec.rb +30 -0
  171. data/spec/client/methods_spec.rb +15 -0
  172. data/spec/client/namespace_spec.rb +19 -0
  173. data/spec/client/repository_spec.rb +39 -0
  174. data/spec/client/session_spec.rb +165 -0
  175. data/spec/client/user_spec.rb +16 -0
  176. data/spec/client_spec.rb +17 -0
  177. data/spec/pro_spec.rb +10 -0
  178. data/spec/spec_helper.rb +29 -0
  179. data/spec/support/fake_api.rb +731 -0
  180. data/spec/support/fake_github.rb +24 -0
  181. data/spec/support/fake_travis_config.yml +14 -0
  182. data/spec/support/helpers.rb +45 -0
  183. data/spec/travis_spec.rb +10 -0
  184. data/travis.gemspec +371 -0
  185. metadata +534 -0
@@ -0,0 +1,36 @@
1
+ require 'travis/client/weak_entity'
2
+
3
+ module Travis
4
+ module Client
5
+ class Request < WeakEntity
6
+ # @!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
8
+ time :created_at
9
+
10
+ # @!parse attr_reader :repository
11
+ has :repository, :commit
12
+
13
+ one :request
14
+ many :requests
15
+
16
+ def owner
17
+ repository.owner
18
+ end
19
+
20
+ def accepted?
21
+ result == 'accepted'
22
+ end
23
+
24
+ def rejected?
25
+ result == 'rejected'
26
+ end
27
+
28
+ def inspect_info
29
+ [
30
+ repository && repository.slug,
31
+ event_type, branch || pull_request_number, result
32
+ ].compact.join(" ")
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ require 'travis/client'
2
+
3
+ module Travis
4
+ module Client
5
+ module Restartable
6
+ def restartable?
7
+ true
8
+ end
9
+
10
+ def restart
11
+ session.restart(self)
12
+ end
13
+
14
+ def cancelable?
15
+ true
16
+ end
17
+
18
+ def cancel
19
+ session.cancel(self)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,339 @@
1
+ require 'travis/client'
2
+ require 'travis/version'
3
+
4
+ require 'faraday'
5
+ require 'faraday_middleware'
6
+ require 'travis/tools/system'
7
+ require 'travis/tools/assets'
8
+
9
+ begin
10
+ require 'typhoeus/adapters/faraday' unless Travis::Tools::System.windows?
11
+ rescue LoadError
12
+ end
13
+
14
+ require 'json'
15
+
16
+ module Travis
17
+ module Client
18
+ class Session
19
+ PRIMITIVE = [nil, false, true]
20
+ SSL_OPTIONS = { :ca_file => Tools::Assets['cacert.pem'] }
21
+
22
+ include Methods
23
+ attr_reader :connection, :headers, :access_token, :instruments, :faraday_adapter, :agent_info, :ssl
24
+ attr_accessor :debug_http
25
+
26
+ def initialize(options = Travis::Client::ORG_URI)
27
+ @headers = {}
28
+ @cache = {}
29
+ @instruments = []
30
+ @agent_info = []
31
+ @config = nil
32
+ @faraday_adapter = defined?(Typhoeus) ? :typhoeus : :net_http
33
+ @ssl = SSL_OPTIONS
34
+
35
+ options = { :uri => options } unless options.respond_to? :each_pair
36
+ options.each_pair { |key, value| public_send("#{key}=", value) }
37
+
38
+ raise ArgumentError, "neither :uri nor :connection specified" unless connection
39
+ headers['Accept'] = 'application/vnd.travis-ci.2+json'
40
+ set_user_agent
41
+ check_ssl
42
+ end
43
+
44
+ def uri
45
+ connection.url_prefix.to_s if connection
46
+ end
47
+
48
+ def agent_info=(info)
49
+ @agent_info = [info].flatten.freeze
50
+ set_user_agent
51
+ end
52
+
53
+ def ssl=(options)
54
+ @ssl = options.dup.freeze
55
+ self.uri = uri if uri
56
+ end
57
+
58
+ def uri=(uri)
59
+ clear_cache!
60
+ self.connection = Faraday.new(:url => uri, :ssl => ssl) do |faraday|
61
+ faraday.request :url_encoded
62
+ faraday.response :logger if debug_http
63
+ faraday.adapter(*faraday_adapter)
64
+ end
65
+ end
66
+
67
+ def faraday_adapter=(adapter)
68
+ @faraday_adapter = adapter
69
+ self.uri &&= uri
70
+ set_user_agent
71
+ end
72
+
73
+ def access_token=(token)
74
+ clear_cache!
75
+ @access_token = token
76
+ headers['Authorization'] = "token #{token}"
77
+ headers.delete('Authorization') unless token
78
+ end
79
+
80
+ def connection=(connection)
81
+ clear_cache!
82
+ connection.headers.merge! headers
83
+ @config = nil
84
+ @connection = connection
85
+ @headers = connection.headers
86
+ end
87
+
88
+ def headers=(headers)
89
+ clear_cache!
90
+ connection.headers = headers if connection
91
+ @headers = headers
92
+ end
93
+
94
+ def find_one(entity, id = nil)
95
+ raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) and entity.many
96
+ return create_entity(entity, entity.id_field => id) if entity.id? id
97
+ cached(entity, :by, id) { fetch_one(entity, id) }
98
+ end
99
+
100
+ def find_many(entity, args = {})
101
+ raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) and entity.many
102
+ cached(entity, :many, args) { fetch_many(entity, args) }
103
+ end
104
+
105
+ def find_one_or_many(entity, args = nil)
106
+ raise Travis::Client::Error, "cannot fetch #{entity}" unless entity.respond_to?(:many) and entity.many
107
+ cached(entity, :one_or_many, args) do
108
+ path = "/#{entity.many}"
109
+ path, args = "#{path}/#{args}", {} unless args.is_a? Hash
110
+ result = get(path, args)
111
+ one = result[entity.one]
112
+
113
+ if result.include? entity.many
114
+ Array(one) + Array(result[entity.many])
115
+ else
116
+ one
117
+ end
118
+ end
119
+ end
120
+
121
+ def reset(entity)
122
+ entity.attributes.clear
123
+ entity
124
+ end
125
+
126
+ def reload(entity)
127
+ reset(entity)
128
+ result = fetch_one(entity.class, entity.id)
129
+ entity.update_attributes(result.attributes) if result.attributes != entity.attributes
130
+ result
131
+ end
132
+
133
+ def config
134
+ @config ||= get_raw('/config')['config'] || {}
135
+ end
136
+
137
+ def load(data)
138
+ result = {}
139
+ (data || {}).each_pair do |key, value|
140
+ entity = load_entity(key, value)
141
+ result[key] = entity if entity
142
+ end
143
+ result
144
+ end
145
+
146
+ def load_entity(key, value)
147
+ type = Entity.subclass_for(key)
148
+ if value.respond_to? :to_ary
149
+ value.to_ary.map { |e| create_entity(type, e) }
150
+ else
151
+ create_entity(type, value)
152
+ end
153
+ rescue IndexError
154
+ end
155
+
156
+ def preload(list)
157
+ list.group_by(&:class).each do |type, instances|
158
+ next unless type.preloadable?
159
+ ids = instances.map { |e| e.id unless e.complete? }.compact
160
+ find_many(type, :ids => ids) if ids.any?
161
+ end
162
+ list
163
+ end
164
+
165
+ def get(*args)
166
+ load get_raw(*args)
167
+ end
168
+
169
+ def delete(*args)
170
+ load delete_raw(*args)
171
+ end
172
+
173
+ def patch(*args)
174
+ load patch_raw(*args)
175
+ end
176
+
177
+ def post(*args)
178
+ load post_raw(*args)
179
+ end
180
+
181
+ def put(*args)
182
+ load put_raw(*args)
183
+ end
184
+
185
+ def get_raw(*args)
186
+ raw(:get, *args)
187
+ end
188
+
189
+ def post_raw(*args)
190
+ raw(:post, *args)
191
+ end
192
+
193
+ def put_raw(*args)
194
+ raw(:put, *args)
195
+ end
196
+
197
+ def patch_raw(*args)
198
+ raw(:patch, *args)
199
+ end
200
+
201
+ def delete_raw(*args)
202
+ raw(:delete, *args)
203
+ end
204
+
205
+ def raw(verb, url, *args)
206
+ url = url.sub(/^\//, '')
207
+ result = instrumented(verb.to_s.upcase, url, *args) do
208
+ if url !~ /^https?:/ or url.start_with? api_endpoint
209
+ connection.public_send(verb, url, *args)
210
+ else
211
+ Faraday.public_send(verb, url, *args) { |r| r.headers.delete("Authorization") }
212
+ end
213
+ end
214
+
215
+ case result.status
216
+ when 0 then raise Travis::Client::SSLError, 'SSL error: could not verify peer'
217
+ when 200..299 then JSON.parse(result.body) rescue result.body
218
+ when 301, 303 then raw(:get, result.headers['Location'])
219
+ when 302, 307, 308 then raw(verb, result.headers['Location'])
220
+ when 401 then raise Travis::Client::NotLoggedIn, 'not logged in'
221
+ when 403 then raise Travis::Client::NotLoggedIn, 'invalid access token'
222
+ when 404 then raise Travis::Client::NotFound, result.body
223
+ when 422 then raise Travis::Client::ValidationFailed, result.body
224
+ when 400..499 then raise Travis::Client::Error, "%s: %p" % [result.status, result.body]
225
+ when 500..599 then raise Travis::Client::Error, "server error (%s: %p)" % [result.status, result.body]
226
+ else raise Travis::Client::Error, "unhandled status code #{result.status}"
227
+ end
228
+ end
229
+
230
+ def inspect
231
+ "#<#{self.class}: #{uri}>"
232
+ end
233
+
234
+ def clear_cache
235
+ reset_entities
236
+ clear_find_cache
237
+ self
238
+ end
239
+
240
+ def clear_cache!
241
+ reset_entities
242
+ @cache.clear
243
+ self
244
+ end
245
+
246
+ def session
247
+ self
248
+ end
249
+
250
+ def instrument(&block)
251
+ instruments << block
252
+ end
253
+
254
+ def private_channels?
255
+ !!config['pusher']['private']
256
+ end
257
+
258
+ private
259
+
260
+ def set_user_agent
261
+ adapter = Array === faraday_adapter ? faraday_adapter.first : faraday_adapter
262
+ adapter = adapter.to_s.capitalize.gsub(/_http_(.)/) { "::HTTP::#{$1.upcase}" }.gsub(/_http/, '::HTTP')
263
+ headers['User-Agent'] = "Travis/#{Travis::VERSION} (#{Travis::Tools::System.description(agent_info)}) Faraday/#{Faraday::VERSION} #{adapter}/#{adapter_version(adapter)}"
264
+ end
265
+
266
+ def adapter_version(adapter)
267
+ version = Object.const_get(adapter).const_get("VERSION")
268
+ [*version].join('.')
269
+ rescue Exception
270
+ "unknown"
271
+ end
272
+
273
+ def instrumented(name, *args)
274
+ name = [name, *args.map(&:inspect)].join(" ") if args.any?
275
+ result = nil
276
+ chain = instruments + [proc { |n,l| result = yield }]
277
+ lift = proc { chain.shift.call(name, lift) }
278
+ lift.call
279
+ result
280
+ end
281
+
282
+ def create_entity(type, data)
283
+ return data if primitive?(data)
284
+ data = { type.id_field => data } if type.id? data
285
+ id = type.cast_id(data.fetch(type.id_field)) unless type.weak?
286
+ entity = id ? cached(type, :id, id) { type.new(self, id) } : type.new(self, nil)
287
+ entity.update_attributes(data)
288
+ entity
289
+ end
290
+
291
+ def primitive?(data)
292
+ PRIMITIVE.include? data
293
+ end
294
+
295
+ def error_message(e)
296
+ message = e.response[:body].to_str rescue e.message
297
+ JSON.parse(message).fetch('error').fetch('message') rescue message
298
+ end
299
+
300
+ def reset_entities
301
+ subcaches do |subcache|
302
+ subcache[:id].each_value { |e| e.attributes.clear } if subcache.include? :id
303
+ end
304
+ end
305
+
306
+ def clear_find_cache
307
+ subcaches do |subcache|
308
+ subcache.delete_if { |k, v| k != :id }
309
+ end
310
+ end
311
+
312
+ def subcaches
313
+ @cache.each_value do |subcache|
314
+ yield subcache if subcache.is_a? Hash
315
+ end
316
+ end
317
+
318
+ def fetch_one(entity, id = nil)
319
+ get("/#{entity.base_path}/#{id}")[entity.one]
320
+ end
321
+
322
+ def fetch_many(entity, params = {})
323
+ get("/#{entity.base_path}/", params)[entity.many]
324
+ end
325
+
326
+ def cached(*keys)
327
+ last = keys.pop
328
+ cache = keys.inject(@cache) { |store, key| store[key] ||= {} }
329
+ cache[last] ||= yield
330
+ end
331
+
332
+ def check_ssl
333
+ raw(:head, '/') if ssl == SSL_OPTIONS
334
+ rescue Exception => error
335
+ self.ssl = {} if error.class == Travis::Client::SSLError
336
+ end
337
+ end
338
+ end
339
+ end
@@ -0,0 +1,25 @@
1
+ require 'travis/client/weak_entity'
2
+ require 'json'
3
+
4
+ module Travis
5
+ module Client
6
+ class Settings < WeakEntity
7
+ attr_accessor :repository
8
+ # @!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, :auto_cancel_pushes, :auto_cancel_pull_requests
10
+ one :settings
11
+ many :settings
12
+
13
+ def save
14
+ raise "repository unknown" unless repository
15
+ result = session.patch("/repos/#{repository.id}/settings", JSON.dump("settings" => attributes))
16
+ attributes.replace(result['settings'].attributes)
17
+ self
18
+ end
19
+
20
+ def inspect_info
21
+ repository ? repository.slug : repository
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+
3
+ module Travis
4
+ module Client
5
+ class SingletonSetting < Entity
6
+ def self.base_path
7
+ "settings/#{one}"
8
+ end
9
+
10
+ has :repository
11
+
12
+ def repository_id
13
+ id
14
+ end
15
+
16
+ def path
17
+ "#{self.class.base_path}/#{id}"
18
+ end
19
+
20
+ def update(values = {})
21
+ values = { 'value' => values } unless values.is_a? Hash
22
+ values.each { |key, value| attributes[key.to_s] = value.to_s }
23
+ session.patch_raw(path, JSON.dump(self.class.one => attributes))
24
+ reload
25
+ end
26
+
27
+ def delete
28
+ session.delete_raw(path)
29
+ reload
30
+ true
31
+ end
32
+
33
+ alias save update
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ module Travis
4
+ module Client
5
+ class SshKey < SingletonSetting
6
+ attributes :description, :fingerprint
7
+ one :ssh_key
8
+ many :ssh_keys
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,98 @@
1
+ require 'travis/client'
2
+
3
+ module Travis
4
+ module Client
5
+ module States
6
+ STATES = %w[created queued received started passed failed errored canceled ready]
7
+
8
+ def ready?
9
+ state == 'ready'
10
+ end
11
+
12
+ def pending?
13
+ check_state
14
+ %w[created started queued received ].include? state
15
+ end
16
+
17
+ def started?
18
+ check_state
19
+ state != 'created' and state != 'received' and state != 'queued'
20
+ end
21
+
22
+ def received?
23
+ check_state
24
+ state != 'created' and state != 'queued'
25
+ end
26
+
27
+ def queued?
28
+ check_state
29
+ state != 'created'
30
+ end
31
+
32
+ def finished?
33
+ not pending?
34
+ end
35
+
36
+ def passed?
37
+ check_state
38
+ state == 'passed'
39
+ end
40
+
41
+ def errored?
42
+ check_state
43
+ state == 'errored'
44
+ end
45
+
46
+ def failed?
47
+ check_state
48
+ state == 'failed'
49
+ end
50
+
51
+ def canceled?
52
+ check_state
53
+ state == 'canceled'
54
+ end
55
+
56
+ def unsuccessful?
57
+ errored? or failed? or canceled?
58
+ end
59
+
60
+ def created?
61
+ check_state
62
+ !!state
63
+ end
64
+
65
+ def color
66
+ case state
67
+ when 'created', 'queued', 'received', 'started' then 'yellow'
68
+ when 'passed', 'ready' then 'green'
69
+ when 'errored', 'canceled', 'failed' then 'red'
70
+ end
71
+ end
72
+
73
+ def yellow?
74
+ color == 'yellow'
75
+ end
76
+
77
+ def green?
78
+ color == 'green'
79
+ end
80
+
81
+ def red?
82
+ color == 'red'
83
+ end
84
+
85
+ def running?
86
+ state == 'started'
87
+ end
88
+
89
+ alias successful? passed?
90
+
91
+ private
92
+
93
+ def check_state
94
+ raise Error, "unknown state %p for %p" % [state, self] unless STATES.include? state
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,67 @@
1
+ require 'travis/client'
2
+
3
+ module Travis
4
+ module Client
5
+ class User < Entity
6
+ # @!parse attr_reader :login, :name, :email, :gravatar_id, :locale, :is_syncing, :synced_at, :correct_scopes
7
+ attributes :login, :name, :email, :gravatar_id, :locale, :is_syncing, :synced_at, :correct_scopes, :channels
8
+ inspect_info :login
9
+
10
+ one :user
11
+ many :users
12
+
13
+ def synced_at=(time)
14
+ set_attribute(:synced_at, time(time))
15
+ end
16
+
17
+ def sync
18
+ session.post_raw('/users/sync')
19
+ reload
20
+ end
21
+
22
+ def channels
23
+ load_attribute(:is_syncing) # dummy to trigger load, as channels might not be included
24
+ attributes['channels'] ||= ['common']
25
+ end
26
+
27
+ def permissions
28
+ attributes['permissions'] ||= begin
29
+ repos = session.get('/users/permissions')
30
+ repos.each_value { |r| r.compact! }
31
+ repos
32
+ end
33
+ end
34
+
35
+ def repositories
36
+ permissions['permissions']
37
+ end
38
+
39
+ def push_access
40
+ permissions['push']
41
+ end
42
+
43
+ def pull_access
44
+ permissions['pull']
45
+ end
46
+
47
+ def admin_access
48
+ permissions['admin']
49
+ end
50
+
51
+ def push_access?(repo)
52
+ push_access.include? repo
53
+ end
54
+
55
+ def pull_access?(repo)
56
+ pull_access.include? repo
57
+ end
58
+
59
+ def admin_access?(repo)
60
+ admin_access.include? repo
61
+ end
62
+
63
+ alias syncing? is_syncing
64
+ alias correct_scopes? correct_scopes
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,26 @@
1
+ require 'travis/client'
2
+
3
+ module Travis
4
+ module Client
5
+ class WeakEntity < Entity
6
+ include NotLoadable
7
+
8
+ def self.weak?
9
+ true
10
+ end
11
+
12
+ def self.id_field
13
+ raise "weak entities do not have id fields"
14
+ end
15
+
16
+ def self.id?(object)
17
+ object.nil?
18
+ end
19
+
20
+ def self.cast_id(object)
21
+ return object if id? object
22
+ raise "weak entities do not have id fields"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'backports/2.0.0' if RUBY_VERSION < '2.0.0'
2
+ require 'travis/client/error'
3
+ require 'travis/client/states'
4
+ require 'travis/client/restartable'
5
+ require 'travis/client/not_loadable'
6
+ require 'travis/client/has_uuid'
7
+ require 'travis/client/methods'
8
+ require 'travis/client/session'
9
+ require 'travis/client/entity'
10
+ require 'travis/client/user'
11
+ require 'travis/client/repository'
12
+ require 'travis/client/env_var'
13
+ require 'travis/client/build'
14
+ require 'travis/client/artifact'
15
+ require 'travis/client/cache'
16
+ require 'travis/client/commit'
17
+ require 'travis/client/job'
18
+ require 'travis/client/namespace'
19
+ require 'travis/client/account'
20
+ require 'travis/client/broadcast'
21
+ require 'travis/client/settings'
22
+ require 'travis/client/singleton_setting'
23
+ require 'travis/client/ssh_key'
24
+ require 'travis/client/request'
25
+ require 'travis/client/listener'
26
+ require 'travis/client/lint_result'
27
+
28
+ module Travis
29
+ module Client
30
+ ORG_URI = 'https://api.travis-ci.org/'
31
+ COM_URI = 'https://api.travis-ci.com/'
32
+
33
+ def self.new(options = {})
34
+ options[:uri] ||= ORG_URI if options.is_a? Hash and not options['uri']
35
+ Session.new(options)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ require 'travis/pro'
2
+ require 'travis/client/auto_login'
3
+ Travis::Client::AutoLogin.new(Travis::Pro).authenticate