-
Notifications
You must be signed in to change notification settings - Fork 141
/
jenkins.rb
64 lines (56 loc) · 1.57 KB
/
jenkins.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'open-uri'
module Sources
module Ci
class Jenkins < Sources::Ci::Base
def custom_fields
[
{ :name => "server_url", :title => "Server Url", :mandatory => true },
{ :name => "project", :title => "Project", :mandatory => true },
]
end
# Returns ruby hash:
def get(options = {})
widget = Widget.find(options.fetch(:widget_id))
project = widget.settings.fetch(:project)
server_url = widget.settings.fetch(:server_url)
result = request_build_status(server_url)
result = XML::Parser.string(result).parse rescue result
result["Projects"]["Project"].each do |data|
if data['name'] == project
return {
:label => data["name"],
:last_build_time => Time.parse(data["lastBuildTime"]),
:last_build_status => status(data["lastBuildStatus"]),
:current_status => current_status(data["activity"])
}
end
end
end
def request_build_status(server_url)
url = "#{server_url}/cc.xml"
Rails.logger.debug("Requesting from #{url} ...")
::HttpService.request(url)
end
def status(status)
case status
when /success/i
0
when /failure/i
1
else
-1
end
end
def current_status(status)
case status
when /sleeping/i
0
when /building/i
1
else
-1
end
end
end
end
end