hudson-remote-api 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/hudson-remote-api.gemspec +3 -2
- data/lib/hudson-remote-api.rb +12 -6
- data/lib/hudson-remote-api/config.rb +0 -1
- data/lib/hudson-remote-api/job.rb +33 -7
- data/lib/hudson-remote-api/new_job_config.xml +16 -0
- data/test/test_hudson_job.rb +29 -3
- metadata +5 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/hudson-remote-api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{hudson-remote-api}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dru Ibarra"]
|
12
|
-
s.date = %q{2011-06
|
12
|
+
s.date = %q{2011-09-06}
|
13
13
|
s.description = %q{Connect to Hudson's remote web API}
|
14
14
|
s.email = %q{Druwerd@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/hudson-remote-api/errors.rb",
|
31
31
|
"lib/hudson-remote-api/job.rb",
|
32
32
|
"lib/hudson-remote-api/multicast.rb",
|
33
|
+
"lib/hudson-remote-api/new_job_config.xml",
|
33
34
|
"test/test_hudson_build.rb",
|
34
35
|
"test/test_hudson_build_queue.rb",
|
35
36
|
"test/test_hudson_config.rb",
|
data/lib/hudson-remote-api.rb
CHANGED
@@ -23,7 +23,6 @@ module Hudson
|
|
23
23
|
load_xml_api
|
24
24
|
|
25
25
|
def self.get_xml(url)
|
26
|
-
puts url
|
27
26
|
uri = URI.parse(url)
|
28
27
|
host = uri.host
|
29
28
|
port = uri.port
|
@@ -50,7 +49,7 @@ module Hudson
|
|
50
49
|
self.class.get_xml(path)
|
51
50
|
end
|
52
51
|
|
53
|
-
def send_post_request(url, data={})
|
52
|
+
def self.send_post_request(url, data={})
|
54
53
|
uri = URI.parse(url)
|
55
54
|
host = uri.host
|
56
55
|
port = uri.port
|
@@ -58,22 +57,29 @@ module Hudson
|
|
58
57
|
request = Net::HTTP::Post.new(path)
|
59
58
|
request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
|
60
59
|
request.set_form_data(data)
|
61
|
-
#puts request.to_yaml
|
62
60
|
Net::HTTP.new(host, port).start{|http| http.request(request)}
|
63
61
|
end
|
62
|
+
|
63
|
+
def send_post_request(url, data={})
|
64
|
+
self.class.send_post_request(url, data)
|
65
|
+
end
|
64
66
|
|
65
|
-
def send_xml_post_request(url, xml)
|
67
|
+
def self.send_xml_post_request(url, xml, data=nil)
|
66
68
|
uri = URI.parse(url)
|
67
69
|
host = uri.host
|
68
70
|
port = uri.port
|
69
71
|
path = uri.path
|
72
|
+
path = path+"?"+uri.query if uri.query
|
70
73
|
request = Net::HTTP::Post.new(path)
|
71
74
|
request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
|
75
|
+
request.set_form_data(data) if data
|
72
76
|
request.body = xml
|
73
|
-
#puts request.body
|
74
|
-
#puts request.to_yaml
|
75
77
|
Net::HTTP.new(host, port).start{|http| http.request(request)}
|
76
78
|
end
|
79
|
+
|
80
|
+
def send_xml_post_request(url, xml, data=nil)
|
81
|
+
self.class.send_xml_post_request(url, xml, data)
|
82
|
+
end
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
@@ -31,11 +31,31 @@ module Hudson
|
|
31
31
|
active_jobs
|
32
32
|
end
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def self.get(job_name)
|
35
|
+
job_name.strip!
|
36
|
+
if list.include?(job_name)
|
37
|
+
Job.new(job_name)
|
38
|
+
else
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def initialize(name, config=nil)
|
44
|
+
name.strip!
|
45
|
+
if Job.list.include?(name)
|
46
|
+
@name = name
|
47
|
+
load_xml_api
|
48
|
+
load_config
|
49
|
+
load_info
|
50
|
+
self
|
51
|
+
else
|
52
|
+
j = Job.create(name, config)
|
53
|
+
@name = j.name
|
54
|
+
load_xml_api
|
55
|
+
load_config
|
56
|
+
load_info
|
57
|
+
self
|
58
|
+
end
|
39
59
|
end
|
40
60
|
|
41
61
|
def load_xml_api
|
@@ -97,6 +117,14 @@ module Hudson
|
|
97
117
|
end
|
98
118
|
end
|
99
119
|
|
120
|
+
def self.create(name, config=nil)
|
121
|
+
config = File.open(File.dirname(__FILE__) + '/new_job_config.xml').read if config.nil?
|
122
|
+
|
123
|
+
response = send_post_request(@@xml_api_create_item_path, {:name=>name, :mode=>"hudson.model.FreeStyleProject", :config=>config})
|
124
|
+
raise(APIError, "Error creating job #{name}: #{response.body}") if response.class != Net::HTTPFound
|
125
|
+
Job.get(name)
|
126
|
+
end
|
127
|
+
|
100
128
|
# Create a new job on Hudson server based on the current job object
|
101
129
|
def copy(new_job=nil)
|
102
130
|
new_job = "copy_of_#{@name}" if new_job.nil?
|
@@ -160,13 +188,11 @@ module Hudson
|
|
160
188
|
|
161
189
|
def disable()
|
162
190
|
response = send_post_request(@xml_api_disable_path)
|
163
|
-
puts response.class
|
164
191
|
response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
|
165
192
|
end
|
166
193
|
|
167
194
|
def enable()
|
168
195
|
response = send_post_request(@xml_api_enable_path)
|
169
|
-
puts response.class
|
170
196
|
response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
|
171
197
|
end
|
172
198
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version='1.0' encoding='UTF-8'?>
|
2
|
+
<project>
|
3
|
+
<actions/>
|
4
|
+
<description></description>
|
5
|
+
<keepDependencies>false</keepDependencies>
|
6
|
+
<properties/>
|
7
|
+
<scm class="hudson.scm.NullSCM"/>
|
8
|
+
<canRoam>true</canRoam>
|
9
|
+
<disabled>false</disabled>
|
10
|
+
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
|
11
|
+
<triggers class="vector"/>
|
12
|
+
<concurrentBuild>false</concurrentBuild>
|
13
|
+
<builders/>
|
14
|
+
<publishers/>
|
15
|
+
<buildWrappers/>
|
16
|
+
</project>
|
data/test/test_hudson_job.rb
CHANGED
@@ -16,9 +16,16 @@ class TestHudsonJob < Test::Unit::TestCase
|
|
16
16
|
assert Hudson::Job.list_active
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
19
|
+
def test_create
|
20
|
+
new_job_name = 'new_test_job'
|
21
|
+
new_job = Hudson::Job.create(new_job_name)
|
22
|
+
assert new_job
|
23
|
+
assert_equal(new_job.name, new_job_name)
|
24
|
+
assert new_job.delete
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get
|
28
|
+
job = Hudson::Job.get('test_job')
|
22
29
|
assert job
|
23
30
|
assert_equal 'test_job', job.name, "failed to get job name"
|
24
31
|
end
|
@@ -28,4 +35,23 @@ class TestHudsonJob < Test::Unit::TestCase
|
|
28
35
|
assert job.description
|
29
36
|
assert job.description = "test"
|
30
37
|
end
|
38
|
+
|
39
|
+
def test_new
|
40
|
+
job = Hudson::Job.new('test_job')
|
41
|
+
assert job
|
42
|
+
assert_equal(job.name, 'test_job')
|
43
|
+
|
44
|
+
new_job = Hudson::Job.new('test_job2')
|
45
|
+
assert new_job
|
46
|
+
assert_equal('test_job2', new_job.name)
|
47
|
+
assert new_job.delete
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_copy
|
51
|
+
job = Hudson::Job.get('test_job')
|
52
|
+
new_job = job.copy
|
53
|
+
assert new_job
|
54
|
+
assert_equal(new_job.name, 'copy_of_test_job')
|
55
|
+
assert new_job.delete
|
56
|
+
end
|
31
57
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hudson-remote-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 2
|
9
8
|
- 3
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dru Ibarra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06
|
18
|
+
date: 2011-09-06 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- lib/hudson-remote-api/errors.rb
|
43
43
|
- lib/hudson-remote-api/job.rb
|
44
44
|
- lib/hudson-remote-api/multicast.rb
|
45
|
+
- lib/hudson-remote-api/new_job_config.xml
|
45
46
|
- test/test_hudson_build.rb
|
46
47
|
- test/test_hudson_build_queue.rb
|
47
48
|
- test/test_hudson_config.rb
|