forked from hookdeck/github-contextual-merge-strategy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
52 lines (41 loc) · 1.87 KB
/
script.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
/* global MutationObserver */
function updateStrategy() {
const branch = document.querySelector('.head-ref').textContent;
if (branch === 'release') {
// For PRs targeting the release branch, use Squash and Merge
document.querySelector('.merge-message details button[value=squash]').click();
// Hide the other buttons
document.querySelector('.merge-message details button[value=merge]').style.visibility = "hidden";
document.querySelector('.merge-message details button[value=rebase]').style.visibility = "hidden";
} else if (branch.startsWith('rc/')) {
// For PRs targeting main from rc/* branches, use Merge Commit
document.querySelector('.merge-message details button[value=merge]').click();
// Hide the other buttons
document.querySelector('.merge-message details button[value=squash]').style.visibility = "hidden";
document.querySelector('.merge-message details button[value=rebase]').style.visibility = "hidden";
} else if (branch === 'main') {
// For PRs targeting main from any other branches (including hotfix/*), use Squash and Merge
document.querySelector('.merge-message details button[value=squash]').click();
// Hide the other buttons
document.querySelector('.merge-message details button[value=merge]').style.visibility = "hidden";
document.querySelector('.merge-message details button[value=rebase]').style.visibility = "hidden";
}
}
function main() {
const details = document.querySelector('.merge-message details');
if (details) {
updateStrategy();
}
const actions = document.querySelector('.discussion-timeline-actions');
if (!actions) {
return;
}
const observer = new MutationObserver(() => {
if (document.querySelector('.merge-message details')) {
observer.disconnect();
updateStrategy();
}
});
observer.observe(actions, { subtree: true, childList: true });
}
main();