forked from jenkinsci/pipeline-graph-view-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
108 lines (100 loc) · 3.31 KB
/
build.js
File metadata and controls
108 lines (100 loc) · 3.31 KB
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
/* global notificationBar */
const rerunButton = document.getElementById("pgv-rerun");
if (rerunButton) {
rerunButton.addEventListener("click", (event) => {
event.preventDefault();
async function redirectToNextBuild(queueId) {
while (true) {
try {
const response = await fetch(`nextBuild?queueId=${queueId}`);
if (!response.ok) {
throw new Error(
`Failed to fetch next build data: ${response.status} - ${response.statusText}`,
);
}
const { status, data, message } = await response.json();
if (status === "ok") {
if (data?.nextBuildUrl) {
let root = document.querySelector("head").dataset.rooturl;
if (!root.endsWith("/")) {
root += "/";
}
window.location = `${root}${data.nextBuildUrl}`;
break;
}
} else {
console.warn("Error in next build response:", message);
}
} catch (error) {
console.error("Error fetching next build data:", error);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
const rerunAction = window[`${rerunButton.dataset.proxyName}`];
rerunAction.doRerun(async function (response) {
const { status, data, message } = response.responseJSON;
if (status === "ok") {
notificationBar.show(data.message, notificationBar.SUCCESS);
await redirectToNextBuild(data.queueId);
} else {
const failMessage =
status === "error" && message
? message
: "Unknown error occurred while trying to rerun the build.";
notificationBar.show(failMessage, notificationBar.WARNING);
}
});
});
}
const cancelButton = document.getElementById("pgv-cancel");
if (cancelButton) {
cancelButton.addEventListener("click", (event) => {
event.preventDefault();
const question = cancelButton.getAttribute("data-confirm");
const execute = function () {
const cancelAction = window[`${cancelButton.dataset.proxyName}`];
cancelAction.doCancel(function (response) {
const result = response.responseJSON;
if (result.status === "ok") {
notificationBar.show(cancelButton.dataset.successMessage);
} else {
notificationBar.show(result.message, notificationBar.WARNING);
}
});
};
if (question != null) {
dialog
.confirm(question)
.then(() => {
execute();
return null;
})
.catch((error) => {
console.error("Error in cancel confirm dialog:", error);
});
} else {
execute();
}
});
function updateCancelButton() {
const buildCaption = document.querySelector(".jenkins-build-caption");
const url = buildCaption.dataset.statusUrl;
fetch(url)
.then((rsp) => {
if (rsp.ok) {
const isBuilding = rsp.headers.get("X-Building");
if (isBuilding === "true") {
setTimeout(updateCancelButton, 5000);
} else {
cancelButton.style.display = "none";
}
}
return null;
})
.catch((error) => {
console.error("Error fetching build caption status:", error);
});
}
setTimeout(updateCancelButton, 5000);
}