-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
58 lines (45 loc) · 1.94 KB
/
content.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
// content.js
// Handler when the DOM is fully loaded
console.log("bitbucket-merge-checks - started load!");
function disableMergeButton(button) {
button.setAttribute("title", "Select Squash Merge strategy and check Merge checklist");
button.setAttribute("disabled", "false");
button.setAttribute("style", "background-color: red;");
}
function enableMergeButton(button) {
button.setAttribute("title", "It's safe to merge");
button.setAttribute("style", "background-color: green;");
button.removeAttribute("disabled");
}
function checkMerge() {
//a contains all the button on the page
var buttons = document.getElementsByTagName('button');
//the button we care about is the last button on the page which is the merge button
var button = buttons[buttons.length - 1];
// by default let's disable the merge button.
disableMergeButton(button);
//the value of the choice can be either merge commits or squash
var mergeStrategy = document.getElementsByClassName("select2-chosen");
var mergeStrategyValid = mergeStrategy[0] !== undefined && mergeStrategy[0].innerHTML === "Squash";
// no checklist warnings
var mergeCheckslist = document.getElementsByClassName("field-value");
var mergeCheckslistValid = Array.from(mergeCheckslist).filter(element => {
return element.innerHTML.includes('aui-iconfont-warning');
}).length === 0;
if (mergeStrategyValid && mergeCheckslistValid) {
enableMergeButton(button);
}
}
function checkMergeInterval() {
//sets timeout since we are loading everything with AJAX so we wait a bit that everything loads
setTimeout(checkMerge, 250);
}
document.getElementById("fulfill-pullrequest").onclick = function () {
//sets timeout since we are loading everything with AJAX so we wait a bit that everything loads
setTimeout(function () {
checkMerge()
//keep checking for changes every 0.5 second
setInterval(checkMerge, 500);
}, 250);
};
console.log("bitbucket-merge-checks - Loaded!");