bard 0.25.1 → 0.25.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/bard/ci.rb +30 -13
  3. data/lib/bard/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7a425db1fb81e8ecc60ca4b660d29345e3b7298
4
- data.tar.gz: 304d1b3704221e43956dd9961a2ff6e174c20f62
3
+ metadata.gz: a93db2ad80e6104a194831ff80a71668b59f492d
4
+ data.tar.gz: b97f43d932e49a5d10789e7ac5bcd14401745ce7
5
5
  SHA512:
6
- metadata.gz: 3ff05948b025850324b60f1a66847940e10d411b9d0320632c484dd872ecf40ea82da1d44ea60a98f65edec3e2992d796250a048b14e4e9a864cae26cc85f2b3
7
- data.tar.gz: 16c62d15b3c947c794d62208301ae3d3f273ff5832b5932a5c098ef485f884d90734f2e8267ecf0bff8ba159a32424bb690e4f45ffd5c3e958cc20e08c66560e
6
+ metadata.gz: 3a14f2fd1b3bc0b27e2b1dd7d2d11396c191613064f0285164728d7c07c821af5f1baa031259e9de318241ef42b90e8e76f2a198be60fc2d0dcd40e1f2962c49
7
+ data.tar.gz: 1cb87e22fb668b40b9a4ae3f56712afebac411871976921599cb03da5b8d3e595fba7a148f041a7121856c56abed414382b65841c500af81a4c567c6c186d871
@@ -1,19 +1,18 @@
1
1
  class Bard::CLI < Thor
2
2
  class CI < Struct.new(:project_name, :current_sha)
3
3
  def run
4
- last_build_number = get_last_build_number
5
4
  last_time_elapsed = get_last_time_elapsed
6
5
  start
7
- sleep(2) while last_build_number == get_last_build_number
6
+ sleep(2) until started?
8
7
 
9
8
  start_time = Time.new.to_i
10
- while (self.last_response = `curl -s #{ci_host}/lastBuild/api/xml?token=botandrose`).include? "<building>true</building>"
9
+ while building?
11
10
  elapsed_time = Time.new.to_i - start_time
12
11
  yield elapsed_time, last_time_elapsed
13
12
  sleep(2)
14
13
  end
15
14
 
16
- self.last_response =~ /<result>SUCCESS<\/result>/
15
+ success?
17
16
  end
18
17
 
19
18
  def exists?
@@ -29,24 +28,42 @@ class Bard::CLI < Thor
29
28
 
30
29
  private
31
30
 
31
+ def get_last_time_elapsed
32
+ response = `curl -s #{ci_host}/lastStableBuild/api/xml?token=botandrose`
33
+ response.match(/<duration>(\d+)<\/duration>/)
34
+ $1 ? $1.to_i / 1000 : nil
35
+ end
36
+
32
37
  def ci_host
33
38
  "http://botandrose:thecakeisalie!@ci.botandrose.com/job/#{project_name}"
34
39
  end
35
40
 
36
41
  def start
37
- `curl -s -I -X POST '#{ci_host}/buildWithParameters?token=botandrose&GIT_REF=#{current_sha}'`
42
+ command = "curl -s -I -X POST '#{ci_host}/buildWithParameters?token=botandrose&GIT_REF=#{current_sha}'"
43
+ output = `#{command}`
44
+ @queueId = output[%r{Location: .+/queue/item/(\d+)/}, 1].to_i
38
45
  end
39
46
 
40
- def get_last_build_number
41
- response = `curl -s #{ci_host}/lastBuild/api/xml?token=botandrose`
42
- response.match(/<number>(\d+)<\/number>/)
43
- $1 ? $1.to_i : nil
47
+ def started?
48
+ command = "curl -s -g '#{ci_host}/api/json?depth=1&tree=builds[queueId,number]'"
49
+ output = `#{command}`
50
+ output =~ /"queueId":#{@queueId}\b/
44
51
  end
45
52
 
46
- def get_last_time_elapsed
47
- response = `curl -s #{ci_host}/lastStableBuild/api/xml?token=botandrose`
48
- response.match(/<duration>(\d+)<\/duration>/)
49
- $1 ? $1.to_i / 1000 : nil
53
+ def job_id
54
+ @job_id ||= begin
55
+ output = `curl -s -g '#{ci_host}/api/json?depth=1&tree=builds[queueId,number]'`
56
+ output[/"number":(\d+),"queueId":#{@queueId}\b/, 1].to_i
57
+ end
58
+ end
59
+
60
+ def building?
61
+ self.last_response = `curl -s #{ci_host}/#{job_id}/api/json?tree=building,result`
62
+ last_response.include? '"building":true'
63
+ end
64
+
65
+ def success?
66
+ last_response.include? '"result":"SUCCESS"'
50
67
  end
51
68
  end
52
69
  end
@@ -1,4 +1,4 @@
1
1
  module Bard
2
- VERSION = "0.25.1"
2
+ VERSION = "0.25.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.1
4
+ version: 0.25.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Micah Geisel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-18 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor