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.
@@ -17,9 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
 
19
19
  gem.add_development_dependency "rspec"
20
- gem.add_dependency "rake"
20
+ gem.add_development_dependency "rake"
21
21
  gem.add_dependency "httparty"
22
- gem.add_dependency "nokogiri"
23
22
  # Other attributes omitted
24
-
25
23
  end
@@ -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 = options[: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
@@ -21,7 +21,7 @@ class JenkinsApi
21
21
  end
22
22
 
23
23
  def create_job(job, options = {})
24
- repo, branch_name = job.split('.')
24
+ repo, branch_name = job.split('.', 2)
25
25
  job_config = create_job_configuration(repo, branch_name)
26
26
  options.merge!(
27
27
  :body => job_config,
@@ -1,5 +1,5 @@
1
1
  module Kraken
2
2
  module Build
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -2,122 +2,135 @@ require 'spec_helper'
2
2
 
3
3
  describe JenkinsApi do
4
4
 
5
- context "configurations" do
6
- before(:each) do
7
- api = JenkinsApi.new
8
- end
5
+ context "configurations" do
6
+ before(:each) do
7
+ JenkinsApi.instance_variable_set(:@default_options, {})
8
+ end
9
9
 
10
- it "uses no basic_auth when username and password are not prived" do
11
- pending("flapping")
12
- asd = {:user_name => nil, :password =>"nil"}
13
- api = asd
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
- api.class.default_options[:basic_auth].should be(nil)
17
- end
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
- it "uses basic_auth when username and password prived" do
20
- options = {:username => 'user', :password => 'password'}
21
- api = JenkinsApi.new(options)
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
- api.class.default_options[:basic_auth][:username] == options[:username].should
24
- api.class.default_options[:basic_auth][:password] == options[:password].should
25
- end
23
+ it "uses a port when provided" do
24
+ options = {:host => "host", :port => '1337'}
25
+ api = JenkinsApi.new(options)
26
26
 
27
- it "uses a port when provided" do
28
- options = {:host => "host", :port => '1337'}
29
- api = JenkinsApi.new(options)
27
+ api.class.default_options[:base_uri].should == 'http://host:1337'
28
+ end
30
29
 
31
- api.class.default_options[:base_uri].should == 'http://host:1337'
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
- context "when interacting with Jenkins" do
38
- before(:each) do
39
- @api = JenkinsApi.new
40
- end
38
+ it "#get_jobs returns an array of jobs" do
39
+ j = []
40
+ j << {"name" => "Foo"}
41
+ j << {"name" => "Bar"}
41
42
 
42
- it "#get_jobs returns an array of jobs" do
43
- j = []
44
- j << {"name" => "Foo"}
45
- j << {"name" => "Bar"}
43
+ results = {"jobs" => j}
46
44
 
47
- results = {"jobs" => j}
45
+ @api.class.should_receive(:get).and_return(results)
48
46
 
49
- @api.class.should_receive(:get).and_return(results)
47
+ jobs = @api.get_jobs
50
48
 
51
- jobs = @api.get_jobs
49
+ jobs.should include "Foo"
50
+ jobs.should include "Bar"
51
+ end
52
52
 
53
- jobs.should include "Foo"
54
- jobs.should include "Bar"
55
- end
53
+ it "#remove_job returns true if a job was deleted successfully" do
54
+ job_name = "foo.test_branch"
56
55
 
57
- it "#remove_job returns true if a job was deleted successfully" do
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
- @api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
58
+ @api.remove_job(job_name)
59
+ end
61
60
 
62
- @api.remove_job(job_name)
63
- end
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
- it "#build_job returns true and triggers a build for a job" do
66
- @api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
64
+ @api.build_job("FooJob")
65
+ end
67
66
 
68
- @api.build_job("FooJob")
69
- end
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
- xml = double()
76
- xml.should_receive(:body).and_return(a)
70
+ XML
71
+ xml = double()
72
+ xml.should_receive(:body).and_return(a)
77
73
 
78
- @api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
74
+ @api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
79
75
 
80
- @api.get_job_configuration("FooJob").should be(a)
81
- end
76
+ @api.get_job_configuration("FooJob").should be(a)
77
+ end
82
78
 
83
- it "#create_job_configuration returns a valid job configuration" do
84
- xml = <<XML
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
- 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
- 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
- it "creates a new job with a given xml configuration" do
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
- a = <<XML
96
+ a = <<-XML
103
97
  <xml>foo</xml>
104
- XML
105
-
106
- repo = "FooRepo"
107
- branch = "master"
108
- job = "#{repo}.#{branch}"
109
-
110
- job = "FooRepo.master"
111
-
112
- @api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
113
-
114
- @api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}", {
115
- :body => a,
116
- :format => :xml,
117
- :headers => {"content-type"=>"application/xml" }})
118
-
119
- @api.create_job("FooRepo.master")
120
- end
121
- end
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.2
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-07-12 00:00:00.000000000 Z
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: :runtime
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: -1000239270356709481
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: -1000239270356709481
112
+ hash: 3700352147428920212
129
113
  requirements: []
130
114
  rubyforge_project:
131
115
  rubygems_version: 1.8.24