bamboo-client 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -2
- data/lib/bamboo-client/rest.rb +75 -0
- data/lib/bamboo-client/version.rb +1 -1
- data/spec/bamboo-client/rest_spec.rb +60 -0
- data/spec/fixtures/queue.json +12 -0
- data/spec/fixtures/queue_with_no_queued_builds.json +12 -0
- data/spec/fixtures/queue_with_queued_builds.json +25 -0
- data/spec/fixtures/queued_build.json +10 -0
- metadata +17 -4
data/.travis.yml
CHANGED
data/lib/bamboo-client/rest.rb
CHANGED
@@ -53,6 +53,10 @@ module Bamboo
|
|
53
53
|
Plan.new get("plan/#{URI.escape key}").data, @http
|
54
54
|
end
|
55
55
|
|
56
|
+
def queue
|
57
|
+
get("queue/").auto_expand Queue, @http
|
58
|
+
end
|
59
|
+
|
56
60
|
private
|
57
61
|
|
58
62
|
def get(what, params = nil)
|
@@ -254,6 +258,77 @@ module Bamboo
|
|
254
258
|
|
255
259
|
end # Change
|
256
260
|
|
261
|
+
class Queue
|
262
|
+
def initialize(data, http)
|
263
|
+
@data = data
|
264
|
+
@http = http
|
265
|
+
end
|
266
|
+
|
267
|
+
def size
|
268
|
+
@data['queuedBuilds']['size']
|
269
|
+
end
|
270
|
+
|
271
|
+
def add(key)
|
272
|
+
data = @http.post(File.join(SERVICE, "queue/#{URI.escape key}"), {}, @http.cookies).data
|
273
|
+
QueuedBuild.new(data, @http)
|
274
|
+
end
|
275
|
+
|
276
|
+
def queued_builds
|
277
|
+
@queued_builds ||= (
|
278
|
+
unless @data['queuedBuilds'] && @data['queuedBuilds']['queuedBuild']
|
279
|
+
@data = @http.get(File.join(SERVICE, 'queue'), {:expand => 'queuedBuilds'}, @http.cookies).data
|
280
|
+
end
|
281
|
+
|
282
|
+
begin
|
283
|
+
@data.fetch('queuedBuilds').fetch('queuedBuild').map { |e| QueuedBuild.new(e, @http) }
|
284
|
+
rescue IndexError
|
285
|
+
[]
|
286
|
+
end
|
287
|
+
)
|
288
|
+
end
|
289
|
+
end # Queue
|
290
|
+
|
291
|
+
class QueuedBuild
|
292
|
+
def initialize(data, http)
|
293
|
+
@data = data
|
294
|
+
@http = http
|
295
|
+
end
|
296
|
+
|
297
|
+
def url
|
298
|
+
@data.fetch("link")['href']
|
299
|
+
end
|
300
|
+
|
301
|
+
def trigger_reason
|
302
|
+
@data['triggerReason']
|
303
|
+
end
|
304
|
+
|
305
|
+
def build_number
|
306
|
+
@data['buildNumber']
|
307
|
+
end
|
308
|
+
|
309
|
+
def plan_key
|
310
|
+
@data['planKey']
|
311
|
+
end
|
312
|
+
|
313
|
+
def build_result_key
|
314
|
+
@data['buildResultKey']
|
315
|
+
end
|
316
|
+
|
317
|
+
def url
|
318
|
+
@data.fetch("link")['href']
|
319
|
+
end
|
320
|
+
|
321
|
+
def changes
|
322
|
+
@changes ||= (
|
323
|
+
unless @data['changes'] && @data['changes']['change']
|
324
|
+
@data = @http.get(URI.parse(url), {:expand => 'changes'}, @http.cookies).data
|
325
|
+
end
|
326
|
+
|
327
|
+
@data.fetch('changes').fetch('change').map { |e| Change.new(e, @http) }
|
328
|
+
)
|
329
|
+
end
|
330
|
+
end # QueuedBuild
|
331
|
+
|
257
332
|
end # Rest
|
258
333
|
end # Client
|
259
334
|
end # Bamboo
|
@@ -48,6 +48,15 @@ module Bamboo
|
|
48
48
|
client.results.should == %w[foo bar]
|
49
49
|
end
|
50
50
|
|
51
|
+
it "should be able to fetch the queue" do
|
52
|
+
document.should_receive(:auto_expand).with(Rest::Queue, http).and_return %w[foo bar]
|
53
|
+
|
54
|
+
http.should_receive(:get).with("/rest/api/latest/queue/", nil, nil).
|
55
|
+
and_return(document)
|
56
|
+
|
57
|
+
client.queue.should == %w[foo bar]
|
58
|
+
end
|
59
|
+
|
51
60
|
it "should be able to fetch results for a specific key" do
|
52
61
|
document.should_receive(:auto_expand).with(Rest::Result, http).and_return %w[foo bar]
|
53
62
|
|
@@ -248,6 +257,57 @@ module Bamboo
|
|
248
257
|
end
|
249
258
|
end
|
250
259
|
|
260
|
+
describe Rest::Queue do
|
261
|
+
let(:data) { json_fixture("queue") }
|
262
|
+
let(:queue) { Rest::Queue.new data, http }
|
263
|
+
|
264
|
+
it "has a size" do
|
265
|
+
queue.size.should == 1
|
266
|
+
end
|
267
|
+
|
268
|
+
it "has a list of queued builds when there are queued builds" do
|
269
|
+
http.should_receive(:get).and_return Http::Json::Doc.new(json_fixture("queue_with_queued_builds"))
|
270
|
+
http.should_receive(:cookies).and_return("some" => "cookie")
|
271
|
+
queue.queued_builds.first.should be_kind_of(Rest::QueuedBuild)
|
272
|
+
end
|
273
|
+
|
274
|
+
it "has an empty list when there are no queued builds" do
|
275
|
+
http.should_receive(:get).and_return Http::Json::Doc.new(json_fixture("queue_with_no_queued_builds"))
|
276
|
+
http.should_receive(:cookies).and_return("some" => "cookie")
|
277
|
+
queue.queued_builds.should be_empty
|
278
|
+
end
|
279
|
+
|
280
|
+
it "can add plan to queue" do
|
281
|
+
http.should_receive(:cookies).and_return("some" => "cookie")
|
282
|
+
http.should_receive(:post).with("/rest/api/latest/queue/DEMOPROJECT-CANARY", {}, {"some" => "cookie"}).and_return Http::Json::Doc.new(json_fixture("queued_build"))
|
283
|
+
queue.add("DEMOPROJECT-CANARY").should be_kind_of(Rest::QueuedBuild)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
describe Rest::QueuedBuild do
|
288
|
+
let(:data) { json_fixture("queued_build") }
|
289
|
+
let(:queued_build) { Rest::QueuedBuild.new data, http }
|
290
|
+
|
291
|
+
it "has a trigger reason" do
|
292
|
+
queued_build.trigger_reason.should == "Code has changed"
|
293
|
+
end
|
294
|
+
|
295
|
+
it "has a build number" do
|
296
|
+
queued_build.build_number.should == 42
|
297
|
+
end
|
298
|
+
|
299
|
+
it "has a plan key" do
|
300
|
+
queued_build.plan_key.should == "DEMOPROJECT-CANARY-JOB1"
|
301
|
+
end
|
302
|
+
|
303
|
+
it "has a build result key" do
|
304
|
+
queued_build.build_result_key.should == "DEMOPROJECT-CANARY-JOB1-42"
|
305
|
+
end
|
306
|
+
|
307
|
+
it "has a url" do
|
308
|
+
queued_build.url.should == "http://localhost:8085/rest/api/latest/result/DEMOPROJECT-CANARY-JOB1-42"
|
309
|
+
end
|
310
|
+
end
|
251
311
|
|
252
312
|
end # Rest
|
253
313
|
end # Client
|
@@ -0,0 +1,25 @@
|
|
1
|
+
{
|
2
|
+
"expand": "queuedBuilds",
|
3
|
+
"link": {
|
4
|
+
"href": "http://localhost:8085/rest/api/latest/queue/",
|
5
|
+
"rel": "self"
|
6
|
+
},
|
7
|
+
"queuedBuilds": {
|
8
|
+
"expand": "queuedBuild",
|
9
|
+
"max-result": 1,
|
10
|
+
"queuedBuild": [
|
11
|
+
{
|
12
|
+
"buildNumber": 42,
|
13
|
+
"buildResultKey": "DEMOPROJECT-CANARY-JOB1-42",
|
14
|
+
"link": {
|
15
|
+
"href": "http://localhost:8085/rest/api/latest/result/DEMOPROJECT-CANARY-JOB1-42",
|
16
|
+
"rel": "self"
|
17
|
+
},
|
18
|
+
"planKey": "DEMOPROJECT-CANARY-JOB1",
|
19
|
+
"triggerReason": "Code has changed"
|
20
|
+
}
|
21
|
+
],
|
22
|
+
"size": 1,
|
23
|
+
"start-index": 0
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"buildNumber": 42,
|
3
|
+
"buildResultKey": "DEMOPROJECT-CANARY-JOB1-42",
|
4
|
+
"link": {
|
5
|
+
"href": "http://localhost:8085/rest/api/latest/result/DEMOPROJECT-CANARY-JOB1-42",
|
6
|
+
"rel": "self"
|
7
|
+
},
|
8
|
+
"planKey": "DEMOPROJECT-CANARY-JOB1",
|
9
|
+
"triggerReason": "Code has changed"
|
10
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bamboo-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -165,6 +165,10 @@ files:
|
|
165
165
|
- spec/fixtures/change.json
|
166
166
|
- spec/fixtures/plan.json
|
167
167
|
- spec/fixtures/project.json
|
168
|
+
- spec/fixtures/queue.json
|
169
|
+
- spec/fixtures/queue_with_no_queued_builds.json
|
170
|
+
- spec/fixtures/queue_with_queued_builds.json
|
171
|
+
- spec/fixtures/queued_build.json
|
168
172
|
- spec/fixtures/result.json
|
169
173
|
- spec/fixtures/result_with_changes.json
|
170
174
|
- spec/spec_helper.rb
|
@@ -180,15 +184,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
180
184
|
- - ! '>='
|
181
185
|
- !ruby/object:Gem::Version
|
182
186
|
version: '0'
|
187
|
+
segments:
|
188
|
+
- 0
|
189
|
+
hash: 1404739530384036117
|
183
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
191
|
none: false
|
185
192
|
requirements:
|
186
193
|
- - ! '>='
|
187
194
|
- !ruby/object:Gem::Version
|
188
195
|
version: '0'
|
196
|
+
segments:
|
197
|
+
- 0
|
198
|
+
hash: 1404739530384036117
|
189
199
|
requirements: []
|
190
200
|
rubyforge_project: bamboo-client
|
191
|
-
rubygems_version: 1.8.
|
201
|
+
rubygems_version: 1.8.25
|
192
202
|
signing_key:
|
193
203
|
specification_version: 3
|
194
204
|
summary: Ruby client for Atlassian Bamboo's REST APIs
|
@@ -208,7 +218,10 @@ test_files:
|
|
208
218
|
- spec/fixtures/change.json
|
209
219
|
- spec/fixtures/plan.json
|
210
220
|
- spec/fixtures/project.json
|
221
|
+
- spec/fixtures/queue.json
|
222
|
+
- spec/fixtures/queue_with_no_queued_builds.json
|
223
|
+
- spec/fixtures/queue_with_queued_builds.json
|
224
|
+
- spec/fixtures/queued_build.json
|
211
225
|
- spec/fixtures/result.json
|
212
226
|
- spec/fixtures/result_with_changes.json
|
213
227
|
- spec/spec_helper.rb
|
214
|
-
has_rdoc:
|