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
82 lines (74 loc) · 2.66 KB
/
build.js
File metadata and controls
82 lines (74 loc) · 2.66 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
/* global notificationBar */
const rerunButton = document.getElementById('pgv-rerun');
if (rerunButton) {
rerunButton.addEventListener('click', event => {
event.preventDefault();
const rerunAction = window[`${rerunButton.dataset.proxyName}`];
function updateNextBuildButton(buildNumber) {
const nextBuild = document.querySelector("[data-module='next-build']");
if (nextBuild) {
nextBuild.classList.remove("jenkins-hidden");
nextBuild.href = nextBuild.dataset.urlPattern.replace("NEXT_BUILD_NUMBER", buildNumber);
nextBuild.removeAttribute("data-module");
nextBuild.removeAttribute("data-url-pattern");
}
}
rerunAction.doRerun(function (success) {
const result = success.responseJSON;
if (result?.status === "ok") {
notificationBar.show(result.data.message, notificationBar.SUCCESS);
updateNextBuildButton(result.data.buildNumber);
} else {
const failMessage = result?.status === "error" && result.data.message ? result.data.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 statsus:", error);
})
}
setTimeout(updateCancelButton, 5000);
}