forked from patforna/cidar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cidar.rb
127 lines (99 loc) · 2.6 KB
/
cidar.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
require 'open-uri'
require 'sinatra'
require 'json'
URL = 'http://ci.lhotse.ov.otto.de:8080/view/'
get '/p13n' do
erb :p13n
end
helpers do
def status_for(project)
@info = Info.new(project)
erb 'status <%= @info.status %>'
end
end
class Info
def initialize(project)
@project = project
@view = JSON.parse(open(URL + project + '/api/json').read)
end
def name
@view['name']
end
def description
@view['description']
end
def jobs
@view['jobs'].collect { |job| Job.new(job['url']) }
end
def success?
jobs.inject(true) { |result, job| result && job.success? }
end
def building?
jobs.inject(false) { |result, job| result || job.building? }
end
def status
building? ? "building" : (success? ? "success" : "failure")
end
def commiters
jobs.inject([]) { |result, job| result += job.commiters}.uniq
end
end
class Job
def initialize(url)
@job = JSON.parse(open(url + '/api/json').read)
@detail = JSON.parse(open(url + '/lastBuild/api/json').read)
end
def name
@job['name']
end
def health
stability = @job['healthReport'].select { |entry| entry ['description'] =~ /Build stability/ }
stability && stability.last()['score']
end
def buildLabel
buildNumber = @job['lastBuild'] && @job['lastBuild']['number']
'#' + buildNumber.to_s + ' ' + (commiter_names_obfuscated() && commiter_names_obfuscated().first()).to_s
end
def status?
"status " + (building? ? "building" : (success? ? "success" : "failure"))
end
def success?
@detail['result'] == "SUCCESS"
end
def building?
@detail['building']
end
def commit_message
if (!@detail['changeSet']['items'].empty?)
@detail['changeSet']['items'].last()['comment']
end
end
def commit_time(fmt)
if (!@detail['changeSet']['items'].empty?)
time = Time.parse(@detail['changeSet']['items'].last()['date']).strftime(fmt)
time ? "@ " + time.to_s : ""
end
end
def commiters
knownNames = commiter_names & knownPeople
if (!(commiter_names - knownNames).empty?)
knownNames << "unknown"
end
knownNames
end
private
def commiter_names_obfuscated()
commiter_names.collect{|name| name.split(" ").collect{|piece| piece[0] + "*" * (piece.length - 1) }.join(" ") }
end
def commiter_names()
@detail['changeSet']['items'].collect { |commit| commit['author']['fullName'] }.uniq
end
def knownPeople()
get_all_image_file_names() - ['unknown']
end
def get_all_image_file_names()
images = []
Dir.entries('public/images').each { |image| images << image[0..-5] }
images
end
end