hudson-remote-api 0.4.2 → 0.5.0
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/README +6 -1
- data/Rakefile +5 -7
- data/VERSION +1 -1
- data/hudson-remote-api.gemspec +11 -11
- data/lib/hudson-remote-api/job.rb +72 -17
- data/test/test_hudson_build.rb +2 -2
- data/test/test_hudson_job.rb +11 -1
- metadata +19 -38
data/README
CHANGED
|
@@ -20,4 +20,9 @@ Hudson::Job.list_active
|
|
|
20
20
|
|
|
21
21
|
# print the last build number of a job
|
|
22
22
|
j = Hudson::Job.new('jobname')
|
|
23
|
-
puts j.last_build
|
|
23
|
+
puts j.last_build
|
|
24
|
+
|
|
25
|
+
# if you are using hudson.plugins.git.GitSCM
|
|
26
|
+
j.repository_url = { :url => 'https://github.com/beeplove/hudson-remote-api-mkhan.git', :branch => 'origin/master' }
|
|
27
|
+
# or, only to change branch
|
|
28
|
+
j.repository_url = { :branch => 'origin/master' }
|
data/Rakefile
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rubygems'
|
|
2
2
|
require 'rake'
|
|
3
|
+
require 'rake/testtask'
|
|
3
4
|
|
|
4
5
|
begin
|
|
5
6
|
require 'jeweler'
|
|
@@ -17,12 +18,9 @@ rescue LoadError
|
|
|
17
18
|
puts "Jeweler not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
task :all do
|
|
23
|
-
test_files = Dir.glob("test/*.rb")
|
|
24
|
-
test_files.each{|f| require f}
|
|
25
|
-
end
|
|
21
|
+
Rake::TestTask.new do |t|
|
|
22
|
+
t.libs << 'test'
|
|
26
23
|
end
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
desc "Run tests"
|
|
26
|
+
task :default => :test
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.5.0
|
data/hudson-remote-api.gemspec
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
|
-
s.name =
|
|
8
|
-
s.version = "0.
|
|
7
|
+
s.name = "hudson-remote-api"
|
|
8
|
+
s.version = "0.5.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
-
s.authors = [
|
|
12
|
-
s.date =
|
|
13
|
-
s.description =
|
|
14
|
-
s.email =
|
|
11
|
+
s.authors = ["Dru Ibarra"]
|
|
12
|
+
s.date = "2012-06-26"
|
|
13
|
+
s.description = "Connect to Hudson's remote web API"
|
|
14
|
+
s.email = "Druwerd@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
16
16
|
"LICENSE",
|
|
17
17
|
"README"
|
|
@@ -36,11 +36,11 @@ Gem::Specification.new do |s|
|
|
|
36
36
|
"test/test_hudson_job.rb",
|
|
37
37
|
"test/test_hudson_multicast.rb"
|
|
38
38
|
]
|
|
39
|
-
s.homepage =
|
|
40
|
-
s.require_paths = [
|
|
41
|
-
s.rubyforge_project =
|
|
42
|
-
s.rubygems_version =
|
|
43
|
-
s.summary =
|
|
39
|
+
s.homepage = "http://github.com/Druwerd/hudson-remote-api"
|
|
40
|
+
s.require_paths = ["lib"]
|
|
41
|
+
s.rubyforge_project = "hudson-remote-api"
|
|
42
|
+
s.rubygems_version = "1.8.24"
|
|
43
|
+
s.summary = "Connect to Hudson's remote web API"
|
|
44
44
|
|
|
45
45
|
if s.respond_to? :specification_version then
|
|
46
46
|
s.specification_version = 3
|
|
@@ -6,6 +6,24 @@ module Hudson
|
|
|
6
6
|
attr_reader :color, :last_build, :last_completed_build, :last_failed_build, :last_stable_build, :last_successful_build, :last_unsuccessful_build, :next_build_number
|
|
7
7
|
attr_reader :builds_list
|
|
8
8
|
|
|
9
|
+
SVN_SCM_CONF = <<-SVN_SCM_STRING
|
|
10
|
+
<scm class="hudson.scm.SubversionSCM">
|
|
11
|
+
<locations>
|
|
12
|
+
<hudson.scm.SubversionSCM_-ModuleLocation>
|
|
13
|
+
<remote>%s</remote>
|
|
14
|
+
<local>.</local>
|
|
15
|
+
</hudson.scm.SubversionSCM_-ModuleLocation>
|
|
16
|
+
</locations>
|
|
17
|
+
<excludedRegions/>
|
|
18
|
+
<includedRegions/>
|
|
19
|
+
<excludedUsers/>
|
|
20
|
+
<excludedRevprop/>
|
|
21
|
+
<excludedCommitMessages/>
|
|
22
|
+
<workspaceUpdater class="hudson.scm.subversion.UpdateUpdater"/>
|
|
23
|
+
</scm>
|
|
24
|
+
SVN_SCM_STRING
|
|
25
|
+
|
|
26
|
+
|
|
9
27
|
# List all Hudson jobs
|
|
10
28
|
def self.list()
|
|
11
29
|
xml = get_xml(@@hudson_xml_api_path)
|
|
@@ -44,7 +62,7 @@ module Hudson
|
|
|
44
62
|
def initialize(name, config=nil)
|
|
45
63
|
name.strip!
|
|
46
64
|
Hudson::Job.fetch_crumb
|
|
47
|
-
if Job.list.include?(name)
|
|
65
|
+
if Job.list.include?(name) # job already in Jenkins
|
|
48
66
|
@name = name
|
|
49
67
|
load_xml_api
|
|
50
68
|
load_config
|
|
@@ -71,24 +89,38 @@ module Hudson
|
|
|
71
89
|
end
|
|
72
90
|
|
|
73
91
|
# Load data from Hudson's Job configuration settings into class variables
|
|
74
|
-
def load_config
|
|
92
|
+
def load_config
|
|
75
93
|
@config = get_xml(@xml_api_config_path)
|
|
76
94
|
@config_doc = REXML::Document.new(@config)
|
|
77
|
-
|
|
78
|
-
@config_doc = REXML::Document.new(@config)
|
|
79
|
-
if !@config_doc.elements["/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote"].nil?
|
|
80
|
-
@repository_url = @config_doc.elements["/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote"].text || ""
|
|
81
|
-
end
|
|
95
|
+
|
|
82
96
|
@repository_urls = []
|
|
83
|
-
if
|
|
84
|
-
@config_doc.elements.each("/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation"){|e| @repository_urls << e.elements["remote"].text }
|
|
85
|
-
end
|
|
86
|
-
if !@config_doc.elements["/project/scm/browser/location"].nil?
|
|
87
|
-
@repository_browser_location = @config_doc.elements["/project/scm/browser/location"].text
|
|
88
|
-
end
|
|
89
|
-
if !@config_doc.elements["/project/description"].nil?
|
|
97
|
+
if @config_doc.elements["/project/description"]
|
|
90
98
|
@description = @config_doc.elements["/project/description"].text || ""
|
|
91
99
|
end
|
|
100
|
+
|
|
101
|
+
if @config_doc.elements["/project/scm"].attributes['class'] == "hudson.plugins.git.GitSCM"
|
|
102
|
+
@git = true
|
|
103
|
+
@repository_url = {}
|
|
104
|
+
if @config_doc.elements["/project/scm/userRemoteConfigs/hudson.plugins.git.UserRemoteConfig/url"]
|
|
105
|
+
@repository_url[:url] = @config_doc.elements['/project/scm/userRemoteConfigs/hudson.plugins.git.UserRemoteConfig/url'].text || ""
|
|
106
|
+
end
|
|
107
|
+
if @config_doc.elements['/project/scm/branches/hudson.plugins.git.BranchSpec/name']
|
|
108
|
+
@repository_url[:branch] = @config_doc.elements['/project/scm/branches/hudson.plugins.git.BranchSpec/name'].text || ""
|
|
109
|
+
end
|
|
110
|
+
if @config_doc.elements['/project/scm/browser/url']
|
|
111
|
+
@repository_browser_location = @config_doc.elements['/project/scm/browser/url'].text || ""
|
|
112
|
+
end
|
|
113
|
+
else
|
|
114
|
+
if !@config_doc.elements["/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote"].nil?
|
|
115
|
+
@repository_url = @config_doc.elements["/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote"].text || ""
|
|
116
|
+
end
|
|
117
|
+
if !@config_doc.elements["/project/scm/locations"].nil?
|
|
118
|
+
@config_doc.elements.each("/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation"){|e| @repository_urls << e.elements["remote"].text }
|
|
119
|
+
end
|
|
120
|
+
if !@config_doc.elements["/project/scm/browser/location"].nil?
|
|
121
|
+
@repository_browser_location = @config_doc.elements["/project/scm/browser/location"].text
|
|
122
|
+
end
|
|
123
|
+
end
|
|
92
124
|
end
|
|
93
125
|
|
|
94
126
|
def load_info()
|
|
@@ -150,10 +182,27 @@ module Hudson
|
|
|
150
182
|
|
|
151
183
|
# Set the repository url and update on Hudson server
|
|
152
184
|
def repository_url=(repository_url)
|
|
153
|
-
return false if @repository_url.nil?
|
|
185
|
+
#return false if @repository_url.nil?
|
|
186
|
+
|
|
154
187
|
@repository_url = repository_url
|
|
155
|
-
|
|
188
|
+
|
|
189
|
+
if @git
|
|
190
|
+
if repository_url[:url]
|
|
191
|
+
@config_doc.elements['/project/scm/userRemoteConfigs/hudson.plugins.git.UserRemoteConfig/url'].text = repository_url[:url]
|
|
192
|
+
end
|
|
193
|
+
if repository_url[:branch]
|
|
194
|
+
@config_doc.elements['/project/scm/branches/hudson.plugins.git.BranchSpec/name'].text = repository_url[:branch]
|
|
195
|
+
end
|
|
196
|
+
else
|
|
197
|
+
if @config_doc.elements["/project/scm"].attributes['class'] == "hudson.scm.NullSCM"
|
|
198
|
+
@config_doc.elements["/project/scm"].replace_with REXML::Document.new(SVN_SCM_CONF % repository_url)
|
|
199
|
+
else
|
|
200
|
+
@config_doc.elements["/project/scm/locations/hudson.scm.SubversionSCM_-ModuleLocation/remote"].text = repository_url
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
156
204
|
@config = @config_doc.to_s
|
|
205
|
+
|
|
157
206
|
update
|
|
158
207
|
end
|
|
159
208
|
|
|
@@ -174,7 +223,11 @@ module Hudson
|
|
|
174
223
|
# Set the repository browser location and update on Hudson server
|
|
175
224
|
def repository_browser_location=(repository_browser_location)
|
|
176
225
|
@repository_browser_location = repository_browser_location
|
|
177
|
-
@
|
|
226
|
+
if @git
|
|
227
|
+
@config_doc.elements['/project/scm/browser/url'].text = repository_browser_location
|
|
228
|
+
else
|
|
229
|
+
@config_doc.elements["/project/scm/browser/location"].text = repository_browser_location
|
|
230
|
+
end
|
|
178
231
|
@config = @config_doc.to_s
|
|
179
232
|
update
|
|
180
233
|
end
|
|
@@ -182,6 +235,8 @@ module Hudson
|
|
|
182
235
|
# Set the job description and update on Hudson server
|
|
183
236
|
def description=(description)
|
|
184
237
|
@description = description
|
|
238
|
+
@config_doc.elements["/project"] << REXML::Element.new("description") if @config_doc.elements["/project/description"].nil?
|
|
239
|
+
|
|
185
240
|
@config_doc.elements["/project/description"].text = description
|
|
186
241
|
@config = @config_doc.to_s
|
|
187
242
|
update
|
data/test/test_hudson_build.rb
CHANGED
|
@@ -11,14 +11,14 @@ class TestHudsonBuild < Test::Unit::TestCase
|
|
|
11
11
|
|
|
12
12
|
def test_build_info
|
|
13
13
|
build = Hudson::Build.new('test_job')
|
|
14
|
-
assert_equal build.job.name
|
|
14
|
+
assert_equal 'test_job', build.job.name
|
|
15
15
|
|
|
16
16
|
assert build.number.to_i > 0, "build number test failed"
|
|
17
17
|
|
|
18
18
|
assert build.revisions, "build revisions test failed"
|
|
19
19
|
assert build.revisions.kind_of?(Hash), "build revisions is not an Hash"
|
|
20
20
|
|
|
21
|
-
assert_equal build.result, "
|
|
21
|
+
assert_equal "SUCCESS", build.result, "build result test failed"
|
|
22
22
|
|
|
23
23
|
assert_nil build.culprit, "build culprit test failed"
|
|
24
24
|
end
|
data/test/test_hudson_job.rb
CHANGED
|
@@ -3,6 +3,7 @@ $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
|
|
3
3
|
require 'hudson-remote-api.rb'
|
|
4
4
|
|
|
5
5
|
class TestHudsonJob < Test::Unit::TestCase
|
|
6
|
+
TEST_SVN_REPO_URL = "http://svn.apache.org/repos/asf/subversion/trunk/doc/user/"
|
|
6
7
|
|
|
7
8
|
def setup
|
|
8
9
|
Hudson[:url] = "http://localhost:8080"
|
|
@@ -32,8 +33,17 @@ class TestHudsonJob < Test::Unit::TestCase
|
|
|
32
33
|
|
|
33
34
|
def test_desc_update
|
|
34
35
|
job = Hudson::Job.new('test_job')
|
|
35
|
-
assert job.description
|
|
36
36
|
assert job.description = "test"
|
|
37
|
+
assert job.description != nil, "Job description should not be nil"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_scm_url
|
|
41
|
+
job = Hudson::Job.new('test_svn_job')
|
|
42
|
+
job.build
|
|
43
|
+
assert job.repository_url = TEST_SVN_REPO_URL
|
|
44
|
+
|
|
45
|
+
job = Hudson::Job.new('test_svn_job')
|
|
46
|
+
assert_equal TEST_SVN_REPO_URL, job.repository_url
|
|
37
47
|
end
|
|
38
48
|
|
|
39
49
|
def test_new
|
metadata
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hudson-remote-api
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
prerelease:
|
|
6
|
-
segments:
|
|
7
|
-
- 0
|
|
8
|
-
- 4
|
|
9
|
-
- 2
|
|
10
|
-
version: 0.4.2
|
|
11
6
|
platform: ruby
|
|
12
|
-
authors:
|
|
7
|
+
authors:
|
|
13
8
|
- Dru Ibarra
|
|
14
9
|
autorequire:
|
|
15
10
|
bindir: bin
|
|
16
11
|
cert_chain: []
|
|
17
|
-
|
|
18
|
-
date: 2012-03-02 00:00:00 Z
|
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
|
19
13
|
dependencies: []
|
|
20
|
-
|
|
21
14
|
description: Connect to Hudson's remote web API
|
|
22
15
|
email: Druwerd@gmail.com
|
|
23
16
|
executables: []
|
|
24
|
-
|
|
25
17
|
extensions: []
|
|
26
|
-
|
|
27
|
-
extra_rdoc_files:
|
|
18
|
+
extra_rdoc_files:
|
|
28
19
|
- LICENSE
|
|
29
20
|
- README
|
|
30
|
-
files:
|
|
21
|
+
files:
|
|
31
22
|
- LICENSE
|
|
32
23
|
- README
|
|
33
24
|
- Rakefile
|
|
@@ -48,36 +39,26 @@ files:
|
|
|
48
39
|
- test/test_hudson_multicast.rb
|
|
49
40
|
homepage: http://github.com/Druwerd/hudson-remote-api
|
|
50
41
|
licenses: []
|
|
51
|
-
|
|
52
42
|
post_install_message:
|
|
53
43
|
rdoc_options: []
|
|
54
|
-
|
|
55
|
-
require_paths:
|
|
44
|
+
require_paths:
|
|
56
45
|
- lib
|
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
47
|
none: false
|
|
59
|
-
requirements:
|
|
60
|
-
- -
|
|
61
|
-
- !ruby/object:Gem::Version
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
- 0
|
|
65
|
-
version: "0"
|
|
66
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ! '>='
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: '0'
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
53
|
none: false
|
|
68
|
-
requirements:
|
|
69
|
-
- -
|
|
70
|
-
- !ruby/object:Gem::Version
|
|
71
|
-
|
|
72
|
-
segments:
|
|
73
|
-
- 0
|
|
74
|
-
version: "0"
|
|
54
|
+
requirements:
|
|
55
|
+
- - ! '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
75
58
|
requirements: []
|
|
76
|
-
|
|
77
59
|
rubyforge_project: hudson-remote-api
|
|
78
|
-
rubygems_version: 1.8.
|
|
60
|
+
rubygems_version: 1.8.24
|
|
79
61
|
signing_key:
|
|
80
62
|
specification_version: 3
|
|
81
63
|
summary: Connect to Hudson's remote web API
|
|
82
64
|
test_files: []
|
|
83
|
-
|