-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.js
84 lines (70 loc) · 3.53 KB
/
builder.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
import * as utils from "./modules/utils.js";
window.addEventListener('load', async e => {
const urlParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlParams.entries());
const builderId = params.builder;
const titleElement = document.getElementById("builderTitle");
const builderInfoUrl = utils.urlFor(`builders/${builderId}`);
const response = await fetch(builderInfoUrl);
if (!response.ok) {
// FIXME use some kind of alert/dialog?
titleElement.innerText = `Failed to fetch info for builder ${builderId}`;
return;
}
response.json().then(data => {
const builderName = data.builders[0].name;
console.log("Got builder " + builderName);
titleElement.innerText = builderName;
document.getElementById("builderName").innerText = builderName;
const builderURL = utils.urlForBuilder(builderId);
document.getElementById("builderURL").appendChild(utils.createLinkFor(builderURL, builderURL));
});
const jobsUrl = utils.urlFor(`builders/${builderId}/builds?limit=100&order=-number&property=identifier`);
const jobsResponse = await fetch(jobsUrl);
if (!jobsResponse.ok) {
// FIXME use some kind of alert?
alert("Failed to fetch jobs");
return;
}
const targetList = document.querySelector('#jobsList > tbody');
jobsResponse.json().then(data => {
const template = document.getElementById('jobListEntry');
data.builds.forEach(element => {
let clone = template.content.firstElementChild.cloneNode(true);
let number_cell = clone.querySelector('.jobNumber');
let number_url = utils.urlForBuilder(`${builderId}/builds/${element.number}`);
let number_link = utils.createLinkFor(number_url, `#${element.number}`);
number_cell.appendChild(number_link);
if (!element.complete) {
number_cell.classList.add('building');
} else if (element.results == 0) {
number_cell.classList.add('success');
} else if (element.results == 2) {
number_cell.classList.add('failure');
}
let started_cell = clone.querySelector('.jobStarted');
let started = utils.formatRelativeDateFromNow(element.started_at, " ago", true);
started_cell.innerText = started;
let identifier_cell = clone.querySelector('.jobIdentifier');
if (element.properties.hasOwnProperty("identifier")) {
let identifier = element.properties.identifier[0];
let identifierURL = `https://commits.webkit.org/${identifier}`;
let identifierLink = utils.createLinkFor(identifierURL, identifier);
identifier_cell.appendChild(identifierLink);
} else {
identifier_cell.textContent = "unknown identifier";
}
let duration_cell = clone.querySelector('.jobDuration');
if (element.complete) {
let duration = utils.formatRelativeDate(element.started_at, element.complete_at, "");
duration_cell.innerText = `${duration}`;
} else {
let duration = utils.formatRelativeDateFromNow(element.started_at);
duration_cell.innerText = `${duration} and counting`;
}
let status_cell = clone.querySelector('.jobStatus');
status_cell.innerText = element.state_string;
targetList.appendChild(clone);
});
});
});