kraken-build 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.
- data/Gemfile +1 -0
- data/lib/kraken-build/jenkins-api.rb +16 -1
- data/lib/kraken-build/version.rb +1 -1
- data/spec/lib/jenkins_api_spec.rb +37 -19
- data/spec/lib/kraken-build_spec.rb +38 -0
- metadata +8 -5
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class JenkinsApi
|
2
2
|
include HTTParty
|
3
3
|
|
4
|
+
attr_accessor :skip_plugins
|
5
|
+
|
4
6
|
def initialize(options = {})
|
5
7
|
if options[:port]
|
6
8
|
self.class.base_uri "#{options[:host]}:#{options[:port]}"
|
@@ -8,9 +10,14 @@ class JenkinsApi
|
|
8
10
|
self.class.base_uri options[:host]
|
9
11
|
end
|
10
12
|
|
11
|
-
if(options[:username] && options[:password])
|
13
|
+
if (options[:username] && options[:password])
|
12
14
|
self.class.basic_auth options[:username] , options[:password]
|
13
15
|
end
|
16
|
+
if (options[:skip_plugins])
|
17
|
+
self.skip_plugins = options[:skip_plugins]
|
18
|
+
else
|
19
|
+
self.skip_plugins = []
|
20
|
+
end
|
14
21
|
end
|
15
22
|
|
16
23
|
def get_jobs(options = {})
|
@@ -35,6 +42,14 @@ class JenkinsApi
|
|
35
42
|
doc = REXML::Document.new(draft)
|
36
43
|
REXML::XPath.first(doc, '//branches//hudson.plugins.git.BranchSpec//name').text = branch
|
37
44
|
|
45
|
+
plugin_names = self.skip_plugins.map { |n| "hudson.plugins.#{n}" }
|
46
|
+
publishers = REXML::XPath.first(doc, '//project/publishers')
|
47
|
+
if publishers && publishers.has_elements? && self.skip_plugins && !(self.skip_plugins.empty?)
|
48
|
+
publishers.children.select { |child| child.xpath.match %r[/hudson\.plugins] }.each do |plugin|
|
49
|
+
doc.delete_element(plugin.xpath) if plugin_names.any? { |name| plugin.xpath[name]}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
38
53
|
doc.to_s
|
39
54
|
end
|
40
55
|
|
data/lib/kraken-build/version.rb
CHANGED
@@ -27,13 +27,17 @@ describe JenkinsApi do
|
|
27
27
|
api.class.default_options[:base_uri].should == 'http://host:1337'
|
28
28
|
end
|
29
29
|
|
30
|
+
it "sets the plugins to skip at initialization" do
|
31
|
+
options = {:skip_plugins => ['test'] }
|
32
|
+
jenkins_api = JenkinsApi.new(options)
|
33
|
+
jenkins_api.skip_plugins.should eq(['test'])
|
34
|
+
end
|
35
|
+
|
30
36
|
end
|
31
37
|
|
32
38
|
|
33
39
|
context "when interacting with Jenkins" do
|
34
|
-
|
35
|
-
@api = JenkinsApi.new
|
36
|
-
end
|
40
|
+
let(:api) { JenkinsApi.new }
|
37
41
|
|
38
42
|
it "#get_jobs returns an array of jobs" do
|
39
43
|
j = []
|
@@ -42,9 +46,9 @@ describe JenkinsApi do
|
|
42
46
|
|
43
47
|
results = {"jobs" => j}
|
44
48
|
|
45
|
-
|
49
|
+
api.class.should_receive(:get).and_return(results)
|
46
50
|
|
47
|
-
jobs =
|
51
|
+
jobs = api.get_jobs
|
48
52
|
|
49
53
|
jobs.should include "Foo"
|
50
54
|
jobs.should include "Bar"
|
@@ -53,15 +57,15 @@ describe JenkinsApi do
|
|
53
57
|
it "#remove_job returns true if a job was deleted successfully" do
|
54
58
|
job_name = "foo.test_branch"
|
55
59
|
|
56
|
-
|
60
|
+
api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
|
57
61
|
|
58
|
-
|
62
|
+
api.remove_job(job_name)
|
59
63
|
end
|
60
64
|
|
61
65
|
it "#build_job returns true and triggers a build for a job" do
|
62
|
-
|
66
|
+
api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
|
63
67
|
|
64
|
-
|
68
|
+
api.build_job("FooJob")
|
65
69
|
end
|
66
70
|
|
67
71
|
it "#get_job_configuration returns the xml configuration for a job" do
|
@@ -71,19 +75,33 @@ describe JenkinsApi do
|
|
71
75
|
xml = double()
|
72
76
|
xml.should_receive(:body).and_return(a)
|
73
77
|
|
74
|
-
|
78
|
+
api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
|
75
79
|
|
76
|
-
|
80
|
+
api.get_job_configuration("FooJob").should be(a)
|
77
81
|
end
|
78
|
-
|
79
|
-
|
80
|
-
|
82
|
+
context "#create_job_configuration" do
|
83
|
+
it "returns a valid job configuration" do
|
84
|
+
xml = <<-XML
|
81
85
|
<xml><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches></xml>
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
XML
|
87
|
+
xml.should_receive(:body).and_return(xml)
|
88
|
+
api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
|
89
|
+
api.create_job_configuration('foobar', 'feature').should =~ /feature/
|
90
|
+
end
|
91
|
+
it "removes all plugins that have been listed in 'skip_plugins'" do
|
92
|
+
api.skip_plugins = ['test']
|
93
|
+
xml_stripped = <<-XML_S
|
94
|
+
<xml><project><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches><publishers></publishers></project></xml>
|
95
|
+
XML_S
|
96
|
+
xml = <<-XML
|
97
|
+
<xml><project><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches><publishers><hudson.plugins.test>test</hudson.plugins.test></publishers></project></xml>
|
98
|
+
XML
|
99
|
+
xml.should_receive(:body).and_return(xml)
|
100
|
+
api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
|
101
|
+
api.create_job_configuration('foobar', 'feature').should_not =~ /hudson\.plugins\.test/
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
87
105
|
|
88
106
|
end
|
89
107
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KrakenBuild do
|
4
|
+
context "Setting config" do
|
5
|
+
let(:options) { mock(Hash).as_null_object }
|
6
|
+
|
7
|
+
it "sets the config options at @config" do
|
8
|
+
kraken = KrakenBuild.set_config(options)
|
9
|
+
KrakenBuild.instance_variable_get(:@config).should eq(options)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "sets the repository option as @repository" do
|
13
|
+
repository = mock(String)
|
14
|
+
options.should_receive(:[]).with(:repository).and_return(repository)
|
15
|
+
kraken = KrakenBuild.set_config(options)
|
16
|
+
KrakenBuild.instance_variable_get(:@repository).should eq(repository)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets the github api from instance call" do
|
20
|
+
github_api = mock(GithubApi).as_null_object
|
21
|
+
GithubApi.should_receive(:new).and_return(github_api)
|
22
|
+
kraken = KrakenBuild.set_config(options)
|
23
|
+
KrakenBuild.instance_variable_get(:@github).should eq(github_api)
|
24
|
+
end
|
25
|
+
it "sets the jenkins api from instance call" do
|
26
|
+
jenkins_api = mock(GithubApi).as_null_object
|
27
|
+
JenkinsApi.should_receive(:new).and_return(jenkins_api)
|
28
|
+
kraken = KrakenBuild.set_config(options)
|
29
|
+
KrakenBuild.instance_variable_get(:@jenkins).should eq(jenkins_api)
|
30
|
+
end
|
31
|
+
it "returns the config" do
|
32
|
+
kraken = KrakenBuild.set_config(options)
|
33
|
+
KrakenBuild.instance_variable_get(:@config).should eq(options)
|
34
|
+
kraken.should eq(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kraken-build
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.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-13 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- .rspec
|
75
75
|
- .travis.yml
|
76
76
|
- Gemfile
|
77
|
+
- Gemfile.lock
|
77
78
|
- LICENSE
|
78
79
|
- README.md
|
79
80
|
- Rakefile
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- lib/kraken-build/version.rb
|
86
87
|
- spec/lib/github_api_spec.rb
|
87
88
|
- spec/lib/jenkins_api_spec.rb
|
89
|
+
- spec/lib/kraken-build_spec.rb
|
88
90
|
- spec/spec_helper.rb
|
89
91
|
homepage: https://github.com/pxlpnk/kraken-build
|
90
92
|
licenses: []
|
@@ -100,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
102
|
version: '0'
|
101
103
|
segments:
|
102
104
|
- 0
|
103
|
-
hash:
|
105
|
+
hash: -3213745627725457868
|
104
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
107
|
none: false
|
106
108
|
requirements:
|
@@ -109,14 +111,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
111
|
version: '0'
|
110
112
|
segments:
|
111
113
|
- 0
|
112
|
-
hash:
|
114
|
+
hash: -3213745627725457868
|
113
115
|
requirements: []
|
114
116
|
rubyforge_project:
|
115
|
-
rubygems_version: 1.8.
|
117
|
+
rubygems_version: 1.8.25
|
116
118
|
signing_key:
|
117
119
|
specification_version: 3
|
118
120
|
summary: Managing your feature branches on Jenkins and Github
|
119
121
|
test_files:
|
120
122
|
- spec/lib/github_api_spec.rb
|
121
123
|
- spec/lib/jenkins_api_spec.rb
|
124
|
+
- spec/lib/kraken-build_spec.rb
|
122
125
|
- spec/spec_helper.rb
|