-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutoMergeDependabotPRs.user.js
123 lines (110 loc) · 2.63 KB
/
AutoMergeDependabotPRs.user.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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// ==UserScript==
// @name Auto Merge Dependabot PRs
// @namespace https://github.com/Nick2bad4u/UserStyles
// @version 1.3
// @description Automatically clicks the merge button on Dependabot PRs and "Done" button on the notification bar
// @author Nick2bad4u
// @match https://github.com/*/*/pull/*
// @grant none
// @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
// @license UnLicense
// ==/UserScript==
(function () {
'use strict';
let lastCheck = 0;
const CHECK_INTERVAL = 1000;
let observer;
function checkAndMerge() {
const now = Date.now();
if (now - lastCheck < CHECK_INTERVAL) return;
lastCheck = now;
console.log('checkAndMerge function called');
const authorElement =
document.querySelector('.author');
if (
authorElement &&
/dependabot(\[bot\])?|Nick2bad4u/.test(
authorElement.textContent.trim(),
)
) {
setTimeout(() => {
const mergeButton =
document.querySelector('.btn.btn-sm');
if (
mergeButton &&
!mergeButton.disabled
) {
console.log(
'Merge button is enabled, clicking it',
);
mergeButton.click();
if (observer) observer.disconnect();
observeDoneButton();
} else {
console.log(
'Merge button is disabled or not found',
);
}
}, 500);
} else {
console.log(
'PR is not created by dependabot',
);
}
}
function observeDoneButton() {
console.log('Observing for Done button...');
const notificationBar =
document.querySelector(
'.js-flash-container',
); // Adjust as necessary
if (!notificationBar) {
console.log('Notification bar not found');
return;
}
const doneButtonObserver =
new MutationObserver(() => {
const doneButton = document.querySelector(
'button[aria-label="Done"].btn.btn-sm',
);
if (doneButton) {
console.log(
'Done button found, clicking it',
);
doneButton.click();
doneButtonObserver.disconnect(); // Stop observing after clicking
}
});
doneButtonObserver.observe(notificationBar, {
childList: true,
subtree: true,
});
}
globalThis.addEventListener(
'load',
function () {
console.log('Page loaded');
const targetNode = document.querySelector(
'.gh-header-meta',
);
if (!targetNode) {
console.log(
'Target node for observation not found',
);
return;
}
observer = new MutationObserver(() => {
console.log(
'Relevant DOM mutation detected',
);
checkAndMerge();
});
observer.observe(targetNode, {
childList: true,
subtree: true,
});
checkAndMerge();
},
false,
);
})();