This repository was archived by the owner on Jun 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathci.js
306 lines (280 loc) · 13.9 KB
/
ci.js
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
// Change this to reflect your environment
var jenkinsPath = 'http://ci.therealtbs.me', // This should point to the root of your Jenkins installation
loadFromExternal = true, // If you are sending your artifacts to a different server (eg. CDN) than your Jenkins installation, set this to true
externalUri = 'http://builds.therealtbs.me/', // If the above is true, set it's URL here
useCredentials = true; // Should we send session cookies with our requests?
$(function () {
$("select").hide();
$.get("http://api.bootswatch.com/3/", function (data) {
var themes = data.themes,
select = $("select");
select.show();
themes.forEach(function (value, index) {
select.append($("<option />")
.val(index)
.text(value.name));
});
select.change(function () {
var theme = themes[$(this).val()];
$("#style").attr("href", theme.cssCdn);
if (typeof(Storage) !== "undefined") {
localStorage.lastTheme = theme.name;
}
});
if (typeof(Storage) !== "undefined" && localStorage.lastTheme != undefined) {
themes.forEach(function (val, nr) {
if (localStorage.lastTheme === val.name) {
select.val(nr);
}
})
} else {
$.each(themes, function (nr, val) {
if (val.name === 'Yeti') {
select.val(nr);
}
});
}
select.change();
}, "json");
if (location.hash === '') {
getOverview();
} else {
getHashSpecific(location.hash.replace('#!', ''));
}
$(window).on('hashchange', function () {
if (location.hash === '') {
getOverview();
} else {
getHashSpecific(location.hash.replace('#!', ''));
}
$("html, body").animate({ scrollTop: 0 }, "slow");
});
});
function getClass(color) {
if (color === 'blue' || color === 'blue_anime') {
return 'panel-success';
}
if (color === 'red' || color === 'red_anime') {
return 'panel-danger';
}
if (color === 'yellow' || color === 'yellow_anime') {
return 'panel-warning';
}
if (color === 'grey' || color === 'grey_anime' || color === 'disabled' || color === 'disabled_anime' ||
color === 'aborted' || color === 'aborted_anime' || color === 'notbuilt' || color === 'notbuilt_anime') {
return 'panel-default';
}
}
function getInfo(color) {
if (color === 'blue' || color === 'blue_anime') {
return 'The last build has succeeded';
}
if (color === 'red' || color === 'red_anime') {
return 'The last build has failed';
}
if (color === 'yellow' || color === 'yellow_anime') {
return 'The last build was marked as unstable';
}
if (color === 'grey' || color === 'grey_anime' || color === 'disabled' || color === 'disabled_anime' ||
color === 'aborted' || color === 'aborted_anime' || color === 'notbuilt' || color === 'notbuilt_anime') {
return 'This project doesn\'t seem to be available';
}
}
function getTableRows(builds, job, limit) {
limit = typeof limit !== 'undefined' ? limit : true;
var html = "";
var nr = 0;
$.each(builds, function (i, build) {
if (nr++ > 10 && limit) return false;
html += '<tr class="' + getTableClass(build.result) + '"><td>' + build.fullDisplayName.replace(job.displayName + ' ', '') + '</td><td>' + formatChangeSet(build.changeSet.items) + '</td><td>' + getDownloadButton(build, job) + '</td></tr>';
});
return html;
}
function formatChangeSet(changeSet) {
var html = '<ol>';
$.each(changeSet, function (i, change) {
html += $('<li></li>').text(change.msg).wrap('<p>').parent().html();
});
return html + '</ol>';
}
function getTableClass(result) {
if (result === 'SUCCESS') {
return 'success';
}
if (result === 'FAILURE') {
return 'danger';
}
if (result === 'UNSTABLE') {
return 'warning';
}
if (result === 'NOT_BUILT' || result === 'ABORTED') {
return '';
}
}
function getDownloadButton(build, job) {
var html;
if (build === null) return 'No download links available';
if (build.result !== "SUCCESS" && build.result != undefined) return 'No download links available';
if (loadFromExternal && build.description === null) return 'No download links available';
if (loadFromExternal && $.parseJSON(build.description).artifacts.length == 0) return 'No download links available';
var artifacts = loadFromExternal ? $.parseJSON(build.description).artifacts : build.artifacts;
if (artifacts.length === 1) {
html = $('<a>', {
'class': 'btn btn-primary btn-xs',
'href': externalUri + job.name + '/' + build.number + '/' + (loadFromExternal ? artifacts[0] : artifacts[0].relativePath)
}).text(loadFromExternal ? artifacts[0] : artifacts[0].fileName);
} else {
html = $('<button>', {
'class': 'btn btn-primary btn-xs',
'onclick': 'showDownloadModal("' + job.displayName + '", "' + build.number + '", \'' + JSON.stringify(artifacts) + '\', "' + job.name + '")'
}).text('Download links');
}
return html.wrap('<p>').parent().html();
}
function showDownloadModal(displayName, number, artifacts, name) {
$('#download').find('.modal-title').text('Download ' + displayName + ' Build #' + number);
if (loadFromExternal) {
$('#download').find('.modal-body').html(listDownloadLinks($.parseJSON(artifacts), name, number));
} else {
$('#').find('.modal-body').html(listDownloadLinks($.parseJSON(artifacts), name, number));
}
$('#download').modal()
}
function listDownloadLinks(artifacts, name, number) {
var html = '';
$.each(artifacts, function (nr, artifact) {
if (loadFromExternal) {
html += '<a class="btn btn-primary" href="' + externalUri + name + '/' + number + '/' + artifact + '">' + artifact + '</a>';
} else {
html += '<a class="btn btn-primary" href="' + jenkinsPath + '/job/' + name + '/' + number + '/artifact/' + artifact.relativePath + '">' + artifact.fileName + '</a>';
}
});
return html;
}
function getOverview() {
$('#overviewBtn').hide();
if (loadFromExternal) {
$.ajax({
dataType: "json",
url: jenkinsPath + '/api/json?tree=jobs[name,color,url,description,displayName,lastSuccessfulBuild[number,description],builds[fullDisplayName,number,result,description,changeSet[items[msg]]]]',
success: function (data) {
$('#content').empty();
for (var i = 0; i < (data.jobs.length / 2); i++) {
$('#content').append('<div class="row"></div>')
}
data.jobs.forEach(function (i) {
var html = '<div class="col-lg-6"><div class="panel ' + getClass(i.color) + '">';
html += '<div class="panel-heading"><span class="panel-title"><a href="#!' + i.name + '">' + i.displayName + '</a></span><i data-toggle="tooltip" data-placement="top" title="' + getInfo(i.color) + '" class="fa fa-question-circle fa-lg pull-right"></i></div>';
html += '<div class=panel-body container"><div class="row"><div class="col-md-8">' + i.description + '</div><div class="col-md-4">';
html += '<h4>Downloads</h4>'
html += getDownloadButton(i.lastSuccessfulBuild, i)
html += '</div></div><hr/></div><table class="table table-striped table-hover"><thead><tr><td>#</td><td>Changes</td><td>Download</td></tr></thead><tbody>' + getTableRows(i.builds, i) + '</tbody></table>';
html += '</div></div>';
$('#content > .row').each(function (nr, i) {
if ($(i).children().length != 2) {
$(i).append(html);
return false;
}
});
});
},
fail: function () {
$('#content').empty();
$('#content').append('<div class="alert alert-danger">Could not retrieve information</div>')
},
xhrFields: {
withCredentials: useCredentials
}
});
} else {
$.ajax({
dataType: "json",
url: jenkinsPath + '/api/json?tree=jobs[name,color,url,description,displayName,lastSuccessfulBuild[number,artifacts[fileName,relativePath]],builds[fullDisplayName,number,result,artifacts[fileName,relativePath],changeSet[items[msg]]]]',
success: function (data) {
$('#content').empty();
for (var i = 0; i < (data.jobs.length / 2); i++) {
$('#content').append('<div class="row"></div>')
}
data.jobs.forEach(function (i) {
var html = '<div class="col-lg-6"><div class="panel ' + getClass(i.color) + '">';
html += '<div class="panel-heading"><span class="panel-title"><a href="#!' + i.name + '">' + i.displayName + '</a></span><i data-toggle="tooltip" data-placement="top" title="' + getInfo(i.color) + '" class="fa fa-question-circle fa-lg pull-right"></i></div>';
html += '<div class=panel-body container"><div class="row"><div class="col-md-8">' + i.description + '</div><div class="col-md-4">';
html += '<h4>Downloads</h4>'
html += getDownloadButton(i.lastSuccessfulBuild, i)
html += '</div></div><hr/></div><table class="table table-striped table-hover"><thead><tr><td>#</td><td>Changes</td><td>Download</td></tr></thead><tbody>' + getTableRows(i.builds, i) + '</tbody></table>';
html += '</div></div>';
$('#content > .row').each(function (nr, i) {
if ($(this).length != 2) {
$(this).append(html);
return false;
}
});
});
},
fail: function () {
$('#content').empty();
$('#content').append('<div class="alert alert-danger">Could not retrieve information</div>')
},
xhrFields: {
withCredentials: useCredentials
}
});
}
}
function getHashSpecific(hashcode) {
$('#overviewBtn').show();
if (loadFromExternal) {
$.ajax({
dataType: "json",
url: jenkinsPath + '/job/' + hashcode + '/api/json?tree=name,color,url,description,displayName,lastSuccessfulBuild[number,description],builds[fullDisplayName,number,result,description,changeSet[items[msg]]]',
success: function (data) {
$('#content').empty();
var i = data;
var html = '<div class="panel ' + getClass(i.color) + '">';
html += '<div class="panel-heading"><span class="panel-title"><a href="#!' + i.name + '">' + i.displayName + '</a></span><i data-toggle="tooltip" data-placement="top" title="' + getInfo(i.color) + '" class="fa fa-question-circle fa-lg pull-right"></i></div>';
html += '<div class=panel-body container"><div class="row"><div class="col-md-8">' + i.description + '</div><div class="col-md-4">';
html += '<h4>Downloads</h4>'
html += getDownloadButton(i.lastSuccessfulBuild, i)
html += '</div></div><hr/></div><table class="table table-striped table-hover"><thead><tr><td>#</td><td>Changes</td><td>Download</td></tr></thead><tbody>' + getTableRows(i.builds, i, false) + '</tbody></table>';
html += '</div>';
$('#content').append(html);
},
fail: function () {
$('#content').empty();
$('#content').append('<div class="alert alert-danger">Could not retrieve information</div>')
},
xhrFields: {
withCredentials: useCredentials
}
});
} else {
$.ajax({
dataType: "json",
url: jenkinsPath + '/job/' + hashcode + '/api/json?tree=name,color,url,description,displayName,lastSuccessfulBuild[number,artifacts[fileName,relativePath]],builds[fullDisplayName,number,result,artifacts[fileName,relativePath],changeSet[items[msg]]]',
success: function (data) {
$('#content').empty();
var i = data;
var html = '<div class="col-lg-6"><div class="panel ' + getClass(i.color) + '">';
html += '<div class="panel-heading"><span class="panel-title"><a href="#!' + i.name + '">' + i.displayName + '</a></span><i data-toggle="tooltip" data-placement="top" title="' + getInfo(i.color) + '" class="fa fa-question-circle fa-lg pull-right"></i></div>';
html += '<div class=panel-body container"><div class="row"><div class="col-md-8">' + i.description + '</div><div class="col-md-4">';
html += '<h4>Downloads</h4>'
html += getDownloadButton(i.lastSuccessfulBuild, i)
html += '</div></div><hr/></div><table class="table table-striped table-hover"><thead><tr><td>#</td><td>Changes</td><td>Download</td></tr></thead><tbody>' + getTableRows(i.builds, i, false) + '</tbody></table>';
html += '</div></div>';
$('#content .row').each(function (nr, i) {
if ($(this).length != 2) {
$(this).append(html);
return false;
}
});
},
fail: function () {
$('#content').empty();
$('#content').append('<div class="alert alert-danger">Could not retrieve information</div>')
},
xhrFields: {
withCredentials: useCredentials
}
});
}
}