kraken-build 0.0.2 → 0.0.3
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/kraken-build.gemspec +1 -3
- data/lib/kraken-build.rb +2 -7
- data/lib/kraken-build/jenkins-api.rb +1 -1
- data/lib/kraken-build/version.rb +1 -1
- data/spec/lib/jenkins_api_spec.rb +100 -87
- metadata +5 -21
data/kraken-build.gemspec
CHANGED
data/lib/kraken-build.rb
CHANGED
@@ -6,13 +6,10 @@ require "kraken-build/version"
|
|
6
6
|
require "kraken-build/jenkins-api.rb"
|
7
7
|
require "kraken-build/github-api.rb"
|
8
8
|
|
9
|
-
|
10
|
-
|
11
9
|
module KrakenBuild
|
12
|
-
|
13
10
|
def self.set_config(options = {})
|
14
11
|
@config = options
|
15
|
-
@repository =
|
12
|
+
@repository = @config[:repository]
|
16
13
|
@github = GithubApi.new(@config)
|
17
14
|
@jenkins = JenkinsApi.new(@config)
|
18
15
|
@jobs = []
|
@@ -22,7 +19,7 @@ module KrakenBuild
|
|
22
19
|
end
|
23
20
|
|
24
21
|
def self.get_jenkins_branches
|
25
|
-
@jenkins.get_jobs.map{ |job| job =~ /^#{@repository}\.(.*)$/ && $1 }.compact
|
22
|
+
@jenkins.get_jobs.map { |job| job =~ /^#{@repository}\.(.*)$/ && $1 }.compact
|
26
23
|
end
|
27
24
|
|
28
25
|
def self.get_github_branches
|
@@ -41,14 +38,12 @@ module KrakenBuild
|
|
41
38
|
@jenkins.build_job(job_name)
|
42
39
|
end
|
43
40
|
|
44
|
-
|
45
41
|
remove = compute_jobs_to_remove
|
46
42
|
remove.map do |job|
|
47
43
|
job_name = "#{@repository}.#{job}"
|
48
44
|
puts "removing => #{job_name}"
|
49
45
|
@jenkins.remove_job(job_name)
|
50
46
|
end
|
51
|
-
|
52
47
|
end
|
53
48
|
|
54
49
|
def self.compute_jobs_to_create
|
data/lib/kraken-build/version.rb
CHANGED
@@ -2,122 +2,135 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe JenkinsApi do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
context "configurations" do
|
6
|
+
before(:each) do
|
7
|
+
JenkinsApi.instance_variable_set(:@default_options, {})
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
api = JenkinsApi.new(asd)
|
10
|
+
it "uses no basic_auth when username and password are not prived" do
|
11
|
+
api = JenkinsApi.new
|
12
|
+
api.class.default_options[:basic_auth].should be(nil)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
it "uses basic_auth when username and password prived" do
|
16
|
+
options = {:username => 'user', :password => 'password'}
|
17
|
+
api = JenkinsApi.new(options)
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
api.class.default_options[:basic_auth][:username].should == options[:username]
|
20
|
+
api.class.default_options[:basic_auth][:password].should == options[:password]
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
it "uses a port when provided" do
|
24
|
+
options = {:host => "host", :port => '1337'}
|
25
|
+
api = JenkinsApi.new(options)
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
api = JenkinsApi.new(options)
|
27
|
+
api.class.default_options[:base_uri].should == 'http://host:1337'
|
28
|
+
end
|
30
29
|
|
31
|
-
|
32
|
-
end
|
30
|
+
end
|
33
31
|
|
34
|
-
end
|
35
32
|
|
33
|
+
context "when interacting with Jenkins" do
|
34
|
+
before(:each) do
|
35
|
+
@api = JenkinsApi.new
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
it "#get_jobs returns an array of jobs" do
|
39
|
+
j = []
|
40
|
+
j << {"name" => "Foo"}
|
41
|
+
j << {"name" => "Bar"}
|
41
42
|
|
42
|
-
|
43
|
-
j = []
|
44
|
-
j << {"name" => "Foo"}
|
45
|
-
j << {"name" => "Bar"}
|
43
|
+
results = {"jobs" => j}
|
46
44
|
|
47
|
-
|
45
|
+
@api.class.should_receive(:get).and_return(results)
|
48
46
|
|
49
|
-
|
47
|
+
jobs = @api.get_jobs
|
50
48
|
|
51
|
-
|
49
|
+
jobs.should include "Foo"
|
50
|
+
jobs.should include "Bar"
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
end
|
53
|
+
it "#remove_job returns true if a job was deleted successfully" do
|
54
|
+
job_name = "foo.test_branch"
|
56
55
|
|
57
|
-
|
58
|
-
job_name = "foo.test_branch"
|
56
|
+
@api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
|
59
57
|
|
60
|
-
|
58
|
+
@api.remove_job(job_name)
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
61
|
+
it "#build_job returns true and triggers a build for a job" do
|
62
|
+
@api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
|
64
63
|
|
65
|
-
|
66
|
-
|
64
|
+
@api.build_job("FooJob")
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
it "#get_job_configuration returns the xml configuration for a job" do
|
72
|
-
a = <<XML
|
67
|
+
it "#get_job_configuration returns the xml configuration for a job" do
|
68
|
+
a = <<-XML
|
73
69
|
<xml>foo</xml>
|
74
|
-
XML
|
75
|
-
|
76
|
-
|
70
|
+
XML
|
71
|
+
xml = double()
|
72
|
+
xml.should_receive(:body).and_return(a)
|
77
73
|
|
78
|
-
|
74
|
+
@api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
|
79
75
|
|
80
|
-
|
81
|
-
|
76
|
+
@api.get_job_configuration("FooJob").should be(a)
|
77
|
+
end
|
82
78
|
|
83
|
-
|
84
|
-
|
79
|
+
it "#create_job_configuration returns a valid job configuration" do
|
80
|
+
xml = <<-XML
|
85
81
|
<xml><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches></xml>
|
86
|
-
XML
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
82
|
+
XML
|
83
|
+
xml.should_receive(:body).and_return(xml)
|
84
|
+
@api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
|
85
|
+
@api.create_job_configuration('foobar', 'feature').should =~ /feature/
|
86
|
+
end
|
92
87
|
|
88
|
+
end
|
93
89
|
|
94
|
-
context "#create_job returns true on the create a job" do
|
95
|
-
before(:each) do
|
96
|
-
@api = JenkinsApi.new
|
97
|
-
end
|
98
90
|
|
99
|
-
|
91
|
+
context "#create_job" do
|
92
|
+
let(:api) { JenkinsApi.new }
|
100
93
|
|
94
|
+
it "creates a new job with a given xml configuration" do
|
101
95
|
|
102
|
-
|
96
|
+
a = <<-XML
|
103
97
|
<xml>foo</xml>
|
104
|
-
XML
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
98
|
+
XML
|
99
|
+
|
100
|
+
repo = "FooRepo"
|
101
|
+
branch = "master"
|
102
|
+
job = "#{repo}.#{branch}"
|
103
|
+
api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
|
104
|
+
api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}",
|
105
|
+
{
|
106
|
+
:body => a,
|
107
|
+
:format => :xml,
|
108
|
+
:headers => {"content-type"=>"application/xml" }
|
109
|
+
})
|
110
|
+
|
111
|
+
api.create_job("FooRepo.master")
|
112
|
+
end
|
113
|
+
|
114
|
+
it "creates a valid job from branches including dots" do
|
115
|
+
a = <<-XML
|
116
|
+
<xml>foo</xml>
|
117
|
+
XML
|
118
|
+
|
119
|
+
repo = "FooRepo"
|
120
|
+
branch = "master"
|
121
|
+
repo = "FooRepo"
|
122
|
+
branch = "master.with.dots"
|
123
|
+
job = "#{repo}.#{branch}"
|
124
|
+
api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
|
125
|
+
api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}",
|
126
|
+
{
|
127
|
+
:body => a,
|
128
|
+
:format => :xml,
|
129
|
+
:headers => {"content-type"=>"application/xml" }
|
130
|
+
})
|
131
|
+
|
132
|
+
api.create_job("FooRepo.master.with.dots")
|
133
|
+
end
|
134
|
+
end
|
122
135
|
|
123
136
|
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.3
|
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: 2012-
|
13
|
+
date: 2012-09-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: '0'
|
39
|
-
type: :
|
39
|
+
type: :development
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
@@ -60,22 +60,6 @@ dependencies:
|
|
60
60
|
- - ! '>='
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
|
-
- !ruby/object:Gem::Dependency
|
64
|
-
name: nokogiri
|
65
|
-
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
|
-
requirements:
|
68
|
-
- - ! '>='
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '0'
|
71
|
-
type: :runtime
|
72
|
-
prerelease: false
|
73
|
-
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
|
-
requirements:
|
76
|
-
- - ! '>='
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
version: '0'
|
79
63
|
description: A simple tool that generates a job for each github branch in your Jenkins
|
80
64
|
environment
|
81
65
|
email:
|
@@ -116,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
100
|
version: '0'
|
117
101
|
segments:
|
118
102
|
- 0
|
119
|
-
hash:
|
103
|
+
hash: 3700352147428920212
|
120
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
105
|
none: false
|
122
106
|
requirements:
|
@@ -125,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
109
|
version: '0'
|
126
110
|
segments:
|
127
111
|
- 0
|
128
|
-
hash:
|
112
|
+
hash: 3700352147428920212
|
129
113
|
requirements: []
|
130
114
|
rubyforge_project:
|
131
115
|
rubygems_version: 1.8.24
|