forked from hookdeck/github-contextual-merge-strategy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
43 lines (35 loc) · 1.29 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
/* global MutationObserver */
function updateStrategy () {
if (['master', 'main', 'staging', 'preview'].includes(document.querySelector('.head-ref').textContent)) {
// If merging from staging or preview (likely to master), do a merge commit
console.log('Clicking merge')
document.querySelector('.merge-message details button[value=merge]').click()
} else {
// Otherwise squash by default
console.log('Clicking squash')
document.querySelector('.merge-message details button[value=squash]').click()
}
}
function main () {
const details = document.querySelector('.merge-message details')
if (details) {
updateStrategy()
// Still watch for updates, needed especially for race conditions in single-page navigation
}
const actions = document.querySelector('.discussion-timeline-actions')
if (!actions) {
// Likely navigation fired before updating DOM but it typically fires again after
return
}
const observer = new MutationObserver(() => {
if (document.querySelector('.merge-message details')) {
observer.disconnect()
console.log('Merge message updated, running')
updateStrategy()
} else {
console.log('Merge message updated, not ready')
}
})
observer.observe(actions, { subtree: true, childList: true })
}
main()