jenkins-remote-api 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
|
|
1
|
+
module Ci
|
2
|
+
class ColorToStatus
|
3
|
+
|
4
|
+
COLOR_STATUS_MAPPING = {
|
5
|
+
/^blue$/ => 'success',
|
6
|
+
/^red$/ => 'failure',
|
7
|
+
/.*anime$/ => 'building',
|
8
|
+
/^disabled$/ => 'disabled',
|
9
|
+
/^aborted$/ => 'aborted',
|
10
|
+
/^yellow$/ => 'unstable', #rare
|
11
|
+
/^grey$/ => 'disabled',
|
12
|
+
}
|
13
|
+
|
14
|
+
def self.get_status_to(color)
|
15
|
+
result_color_key = COLOR_STATUS_MAPPING.keys.find { | color_regex | color_regex.match(color)}
|
16
|
+
raise "This color '#{color}' and its corresponding status hasn't been added to library, pls contact author." if result_color_key.nil?
|
17
|
+
COLOR_STATUS_MAPPING[result_color_key]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,21 +1,12 @@
|
|
1
1
|
require 'libxml'
|
2
2
|
require "#{File.dirname(__FILE__)}/helper/xml_helper.rb"
|
3
|
+
require "#{File.dirname(__FILE__)}/helper/color_to_status.rb"
|
3
4
|
require "#{File.dirname(__FILE__)}/job.rb"
|
4
5
|
module Ci
|
5
6
|
class Jenkins
|
6
7
|
include LibXML
|
7
8
|
include XmlHelper
|
8
9
|
|
9
|
-
COLOR_STATUS_MAPPING = {
|
10
|
-
'^blue$' => 'success',
|
11
|
-
'^red$' => 'failure',
|
12
|
-
'.*anime$' => 'building',
|
13
|
-
'^disabled$' => 'disabled',
|
14
|
-
'^aborted$' => 'aborted',
|
15
|
-
'^yellow$' => 'unstable', #rare
|
16
|
-
'^grey$' => 'disabled',
|
17
|
-
}
|
18
|
-
|
19
10
|
attr_accessor :ci_address
|
20
11
|
|
21
12
|
def initialize url
|
@@ -56,7 +47,7 @@ module Ci
|
|
56
47
|
url = job_doc.find_first('url').content.strip
|
57
48
|
color = job_doc.find_first('color').content.strip
|
58
49
|
{
|
59
|
-
:description => {:name => name, :status => get_status_to(color), :url => url },
|
50
|
+
:description => {:name => name, :status => Ci::ColorToStatus.get_status_to(color), :url => url },
|
60
51
|
:job => Ci::Job.new(url)
|
61
52
|
}
|
62
53
|
}
|
@@ -77,13 +68,7 @@ module Ci
|
|
77
68
|
def xml_url_on_ci
|
78
69
|
url_with_appended_xml(ci_address)
|
79
70
|
end
|
80
|
-
|
81
|
-
def get_status_to color
|
82
|
-
result_color_key = COLOR_STATUS_MAPPING.keys.find { | color_regex | color_regex.match(color)}
|
83
|
-
raise "This color '#{color}' and its corresponding status hasn't been added to library, pls contact author." if result_color_key.nil?
|
84
|
-
COLOR_STATUS_MAPPING[result_color_key]
|
85
|
-
end
|
86
|
-
|
71
|
+
|
87
72
|
def get_job_summary_on job_name
|
88
73
|
targeting_job_summary = jobs_summary.detect{|job_summary| job_summary[:description][:name] == job_name}
|
89
74
|
raise "The job with name 'some job' doesn't exist in job list of #{xml_url_on_ci}.Using jenkins.list_all_job_names to see list." if targeting_job_summary.nil?
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Ci::ColorToStatus do
|
4
|
+
|
5
|
+
it "should get disabled for color grey" do
|
6
|
+
Ci::ColorToStatus.get_status_to("grey").should == "disabled"
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should get disabled for color disabled" do
|
10
|
+
Ci::ColorToStatus.get_status_to("disabled").should == "disabled"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should get successs for color blue" do
|
14
|
+
Ci::ColorToStatus.get_status_to("blue").should == "success"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should get failure for color red" do
|
18
|
+
Ci::ColorToStatus.get_status_to("red").should == "failure"
|
19
|
+
end
|
20
|
+
it "should get aborted for color aborted" do
|
21
|
+
Ci::ColorToStatus.get_status_to("aborted").should == "aborted"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should get disabled for color grey" do
|
25
|
+
Ci::ColorToStatus.get_status_to("yellow").should == "unstable"
|
26
|
+
end
|
27
|
+
|
28
|
+
context "for animation to return building" do
|
29
|
+
it "should get building for color grey_anime" do
|
30
|
+
Ci::ColorToStatus.get_status_to("grey_anime").should == "building"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get building for color grey_anime" do
|
34
|
+
Ci::ColorToStatus.get_status_to("blue_anime").should == "building"
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should get building for color grey_anime" do
|
38
|
+
Ci::ColorToStatus.get_status_to("red_anime").should == "building"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should throw error info when color has no match to status" do
|
43
|
+
expect {
|
44
|
+
Ci::ColorToStatus.get_status_to("unkown")
|
45
|
+
}.to raise_exception("This color 'unkown' and its corresponding status hasn't been added to library, pls contact author.")
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Tuo Huang
|
@@ -134,11 +134,13 @@ files:
|
|
134
134
|
- features/support/env.rb
|
135
135
|
- jenkins-remote-api.gemspec
|
136
136
|
- lib/jenkins-remote-api.rb
|
137
|
+
- lib/jenkins-remote-api/ci/helper/color_to_status.rb
|
137
138
|
- lib/jenkins-remote-api/ci/helper/xml_helper.rb
|
138
139
|
- lib/jenkins-remote-api/ci/jenkins.rb
|
139
140
|
- lib/jenkins-remote-api/ci/job.rb
|
140
141
|
- lib/jenkins-remote-api/cli.rb
|
141
142
|
- lib/jenkins-remote-api/version.rb
|
143
|
+
- spec/color_to_status_spec.rb
|
142
144
|
- spec/jenkins_spec.rb
|
143
145
|
- spec/spec_helper.rb
|
144
146
|
has_rdoc: true
|
@@ -177,5 +179,6 @@ test_files:
|
|
177
179
|
- features/jenkins.feature
|
178
180
|
- features/step_definitions/aruba_steps.rb
|
179
181
|
- features/support/env.rb
|
182
|
+
- spec/color_to_status_spec.rb
|
180
183
|
- spec/jenkins_spec.rb
|
181
184
|
- spec/spec_helper.rb
|