hudson-remote-api 0.3.0 → 0.3.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -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.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Dru Ibarra"]
12
- s.date = %q{2011-09-06}
11
+ s.authors = [%q{Dru Ibarra}]
12
+ s.date = %q{2011-10-05}
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 = [
@@ -39,10 +39,10 @@ Gem::Specification.new do |s|
39
39
  "test/test_hudson_remote_api.rb"
40
40
  ]
41
41
  s.homepage = %q{http://github.com/Druwerd/hudson-remote-api}
42
- s.rdoc_options = ["--charset=UTF-8"]
43
- s.require_paths = ["lib"]
42
+ s.rdoc_options = [%q{--charset=UTF-8}]
43
+ s.require_paths = [%q{lib}]
44
44
  s.rubyforge_project = %q{hudson-remote-api}
45
- s.rubygems_version = %q{1.3.7}
45
+ s.rubygems_version = %q{1.8.5}
46
46
  s.summary = %q{Connect to Hudson's remote web API}
47
47
  s.test_files = [
48
48
  "test/test_hudson_build.rb",
@@ -54,7 +54,6 @@ Gem::Specification.new do |s|
54
54
  ]
55
55
 
56
56
  if s.respond_to? :specification_version then
57
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
57
  s.specification_version = 3
59
58
 
60
59
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -3,6 +3,7 @@
3
3
  # Author:: Dru Ibarra
4
4
 
5
5
  require 'net/http'
6
+ require "net/https"
6
7
  require 'uri'
7
8
  require 'rexml/document'
8
9
  require 'cgi'
@@ -21,7 +22,11 @@ module Hudson
21
22
  end
22
23
 
23
24
  load_xml_api
24
-
25
+
26
+ def self.url_for(path)
27
+ File.join Hudson[:url], path
28
+ end
29
+
25
30
  def self.get_xml(url)
26
31
  uri = URI.parse(url)
27
32
  host = uri.host
@@ -30,7 +35,14 @@ module Hudson
30
35
  request = Net::HTTP::Get.new(path)
31
36
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
32
37
  request['Content-Type'] = "text/xml"
33
- response = Net::HTTP.start(host, port){|http| http.request(request)}
38
+ response = Net::HTTP.start(host, port) do |http|
39
+ http = Net::HTTP.new(uri.host, uri.port)
40
+ if uri.scheme == 'https'
41
+ http.use_ssl = true
42
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
43
+ end
44
+ http.request(request)
45
+ end
34
46
 
35
47
  if response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
36
48
  encoding = response.get_fields("Content-Encoding")
@@ -57,6 +69,7 @@ module Hudson
57
69
  request = Net::HTTP::Post.new(path)
58
70
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
59
71
  request.set_form_data(data)
72
+ request.add_field(crumb.name, crumb.value) if crumb
60
73
  Net::HTTP.new(host, port).start{|http| http.request(request)}
61
74
  end
62
75
 
@@ -73,6 +86,7 @@ module Hudson
73
86
  request = Net::HTTP::Post.new(path)
74
87
  request.basic_auth(Hudson[:user], Hudson[:password]) if Hudson[:user] and Hudson[:password]
75
88
  request.set_form_data(data) if data
89
+ request.add_field(crumb.name, crumb.value) if crumb
76
90
  request.body = xml
77
91
  Net::HTTP.new(host, port).start{|http| http.request(request)}
78
92
  end
@@ -80,6 +94,32 @@ module Hudson
80
94
  def send_xml_post_request(url, xml, data=nil)
81
95
  self.class.send_xml_post_request(url, xml, data)
82
96
  end
97
+
98
+
99
+
100
+ def self.crumb
101
+ @@apiCrumb ||= nil
102
+ end
103
+
104
+ def self.fetch_crumb
105
+ body = get_xml(url_for '/crumbIssuer/api/xml')
106
+ doc = REXML::Document.new(body)
107
+
108
+ crumbValue = doc.elements['/defaultCrumbIssuer/crumb'] or begin
109
+ $stderr.puts "Failure fetching crumb value from server"
110
+ return
111
+ end
112
+
113
+ crumbName = doc.elements['/defaultCrumbIssuer/crumbRequestField'] or begin
114
+ $stderr.puts "Failure fetching crumb field name from server"
115
+ return
116
+ end
117
+
118
+ @@apiCrumb = Struct.new(:name,:value).new(crumbName.text,crumbValue.text)
119
+ rescue
120
+ $stderr.puts "Failure fetching crumb xml"
121
+ end
122
+
83
123
  end
84
124
  end
85
125
 
@@ -1,6 +1,6 @@
1
1
  module Hudson
2
2
  class Build < HudsonObject
3
- attr_reader :number, :job, :revisions, :result
3
+ attr_reader :number, :job, :revisions, :result, :culprit
4
4
 
5
5
  def initialize(job, build_number=nil)
6
6
  @job = Job.new(job) if job.kind_of?(String)
@@ -18,13 +18,24 @@ module Hudson
18
18
  private
19
19
  def load_build_info
20
20
 
21
- build_info_xml = get_xml(@xml_api_build_info_path)
21
+ build_info_xml = patch_bad_git_xml(get_xml(@xml_api_build_info_path))
22
22
  build_info_doc = REXML::Document.new(build_info_xml)
23
-
24
- @result = build_info_doc.elements["/freeStyleBuild/result"].text
23
+
24
+ if build_info_doc.elements["/freeStyleBuild/result"]
25
+ @result = build_info_doc.elements["/freeStyleBuild/result"].text
26
+ end
25
27
  if !build_info_doc.elements["/freeStyleBuild/changeSet"].nil?
26
28
  build_info_doc.elements.each("/freeStyleBuild/changeSet/revision"){|e| @revisions[e.elements["module"].text] = e.elements["revision"].text }
27
29
  end
30
+
31
+ if build_info_doc.elements['/freeStyleBuild/culprit/fullName']
32
+ @culprit = build_info_doc.elements['/freeStyleBuild/culprit/fullName'].text
33
+ end
34
+
28
35
  end
36
+
37
+ def patch_bad_git_xml(xml)
38
+ xml.gsub(/<(\/?)origin\/([_a-zA-Z0-9\-\.]+)>/, '<\1origin-\2>')
39
+ end
29
40
  end
30
41
  end
@@ -42,6 +42,7 @@ module Hudson
42
42
 
43
43
  def initialize(name, config=nil)
44
44
  name.strip!
45
+ Hudson::Job.fetch_crumb
45
46
  if Job.list.include?(name)
46
47
  @name = name
47
48
  load_xml_api
@@ -179,6 +180,10 @@ module Hudson
179
180
  @config = @config_doc.to_s
180
181
  update
181
182
  end
183
+
184
+ def url
185
+ File.join( Hudson[:url], 'job', name) + '/'
186
+ end
182
187
 
183
188
  # Start building this job on Hudson server (can't build parameterized jobs)
184
189
  def build()
@@ -213,4 +218,4 @@ module Hudson
213
218
  response.is_a?(Net::HTTPSuccess) or response.is_a?(Net::HTTPRedirection)
214
219
  end
215
220
  end
216
- end
221
+ end
@@ -4,9 +4,22 @@ require 'hudson-remote-api.rb'
4
4
 
5
5
  class TestHudsonBuild < Test::Unit::TestCase
6
6
 
7
- def test_init
8
- # TODO: load hudson build fixtures
9
- #assert Hudson::Build.new('test_job')
7
+ def setup
8
+ assert Hudson::Job.new('test_job').build
9
+ assert Hudson::Build.new('test_job')
10
+ end
11
+
12
+ def test_build_info
13
+ build = Hudson::Build.new('test_job')
14
+ assert_equal build.job.name, 'test_job'
15
+
16
+ assert build.number.to_i > 0, "build number test failed"
17
+
18
+ assert build.revisions, "build revisions test failed"
19
+
20
+ assert_equal build.result, "SUCCESS", "build result test failed"
21
+
22
+ assert_nil build.culprit, "build culprit test failed"
10
23
  end
11
24
 
12
25
  end
@@ -54,4 +54,9 @@ class TestHudsonJob < Test::Unit::TestCase
54
54
  assert_equal(new_job.name, 'copy_of_test_job')
55
55
  assert new_job.delete
56
56
  end
57
- end
57
+
58
+ def test_url
59
+ job = Hudson::Job.get("test_job")
60
+ assert_equal(job.url, "http://localhost:8080/job/#{job.name}/")
61
+ end
62
+ 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: 19
5
- prerelease: false
4
+ hash: 17
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dru Ibarra
@@ -15,8 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-06 00:00:00 -07:00
19
- default_executable:
18
+ date: 2011-10-05 00:00:00 Z
20
19
  dependencies: []
21
20
 
22
21
  description: Connect to Hudson's remote web API
@@ -49,7 +48,6 @@ files:
49
48
  - test/test_hudson_job.rb
50
49
  - test/test_hudson_multicast.rb
51
50
  - test/test_hudson_remote_api.rb
52
- has_rdoc: true
53
51
  homepage: http://github.com/Druwerd/hudson-remote-api
54
52
  licenses: []
55
53
 
@@ -79,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
77
  requirements: []
80
78
 
81
79
  rubyforge_project: hudson-remote-api
82
- rubygems_version: 1.3.7
80
+ rubygems_version: 1.8.5
83
81
  signing_key:
84
82
  specification_version: 3
85
83
  summary: Connect to Hudson's remote web API