|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Auto-Merge Dependabot PRs |
3 | 3 | // @namespace typpi.online |
4 | | -// @version 6.2 |
| 4 | +// @version 6.3 |
5 | 5 | // @description Merges Dependabot PRs in any of your repositories - pulls the PRs into a table and lets you select which ones to merge. |
6 | 6 | // @author Nick2bad4u |
7 | 7 | // @match https://github.com/notifications |
|
34 | 34 | delay = Number(delay); |
35 | 35 | } |
36 | 36 |
|
| 37 | + /** |
| 38 | + * Shows a modal dialog for secure GitHub token input. |
| 39 | + * @returns {Promise<string>} The entered token. |
| 40 | + */ |
37 | 41 | async function showSecureTokenInputModal() { |
38 | 42 | return new Promise((resolve) => { |
39 | 43 | let modal = document.getElementById('github-token-modal'); |
|
63 | 67 |
|
64 | 68 | document.getElementById('submit-token').addEventListener('click', () => { |
65 | 69 | const tokenInput = document.getElementById('github-token-input').value; |
| 70 | + console.log('[Auto-Merge Dependabot PRs] Token entered via modal.'); |
66 | 71 | modal.remove(); |
67 | 72 | resolve(tokenInput); |
68 | 73 | }); |
69 | 74 | } |
70 | 75 | }); |
71 | 76 | } |
72 | 77 |
|
| 78 | + /** |
| 79 | + * Initializes the script by ensuring a valid token and username are set. |
| 80 | + */ |
73 | 81 | async function initialize() { |
74 | 82 | let token; |
75 | 83 | try { |
76 | 84 | // Attempt to retrieve and decrypt the token |
77 | | - // If the token is not found or decryption fails, it will return an empty string |
78 | 85 | token = await retrieveAndDecryptToken(); |
| 86 | + console.log('[Auto-Merge Dependabot PRs] Token retrieved and decrypted.'); |
79 | 87 | } catch (error) { |
80 | | - console.error('Failed to retrieve and decrypt token:', error); |
| 88 | + console.error('[Auto-Merge Dependabot PRs] Failed to retrieve and decrypt token:', error); |
81 | 89 | alert('Failed to retrieve and decrypt token. Please check the console for more details.'); |
82 | 90 | throw error; // Stop further execution |
83 | 91 | } |
|
91 | 99 | } else { |
92 | 100 | try { |
93 | 101 | await validateGitHubToken(token); |
94 | | - } catch { |
| 102 | + console.log('[Auto-Merge Dependabot PRs] GitHub token validated.'); |
| 103 | + } catch (e) { |
| 104 | + console.error('[Auto-Merge Dependabot PRs] Invalid GitHub token:', e); |
95 | 105 | alert('Invalid GitHub token. Please enter a valid token.'); |
96 | 106 | token = null; |
97 | 107 | } |
98 | 108 | } |
99 | 109 | } |
100 | 110 | try { |
101 | 111 | await encryptAndStoreToken(token); |
| 112 | + console.log('[Auto-Merge Dependabot PRs] Token encrypted and stored.'); |
102 | 113 | } catch (error) { |
103 | | - console.error('Failed to encrypt and store token:', error); |
| 114 | + console.error('[Auto-Merge Dependabot PRs] Failed to encrypt and store token:', error); |
104 | 115 | alert('Failed to encrypt and store token. Please check the console for more details.'); |
105 | 116 | throw error; // Stop further execution |
106 | 117 | } |
|
116 | 127 | try { |
117 | 128 | await validateGitHubUsername(username, token); |
118 | 129 | GM_setValue('github_username', username); |
119 | | - } catch { |
| 130 | + console.log('[Auto-Merge Dependabot PRs] GitHub username validated and saved.'); |
| 131 | + } catch (e) { |
| 132 | + console.error('[Auto-Merge Dependabot PRs] Invalid GitHub username:', e); |
120 | 133 | alert('Invalid GitHub username. Please enter a valid username.'); |
121 | 134 | username = ''; |
122 | 135 | } |
|
126 | 139 | } |
127 | 140 | } |
128 | 141 |
|
| 142 | + /** |
| 143 | + * Validates the GitHub token by making an authenticated request. |
| 144 | + * @param {string} token |
| 145 | + */ |
129 | 146 | async function validateGitHubToken(token) { |
130 | 147 | return new Promise((resolve, reject) => { |
131 | 148 | GM_xmlhttpRequest({ |
|
138 | 155 | if (response.status === 200) { |
139 | 156 | resolve(); |
140 | 157 | } else { |
| 158 | + console.warn('[Auto-Merge Dependabot PRs] Token validation failed:', response.responseText); |
141 | 159 | reject(new Error(`Token validation failed: ${response.responseText}`)); |
142 | 160 | } |
143 | 161 | }, |
144 | 162 | onerror: function (error) { |
| 163 | + console.error('[Auto-Merge Dependabot PRs] Token validation error:', error); |
145 | 164 | reject(error); |
146 | 165 | }, |
147 | 166 | }); |
148 | 167 | }); |
149 | 168 | } |
150 | 169 |
|
| 170 | + /** |
| 171 | + * Validates the GitHub username by making an authenticated request. |
| 172 | + * @param {string} username |
| 173 | + * @param {string} token |
| 174 | + */ |
151 | 175 | async function validateGitHubUsername(username, token) { |
152 | 176 | return new Promise((resolve, reject) => { |
153 | 177 | GM_xmlhttpRequest({ |
|
160 | 184 | if (response.status === 200) { |
161 | 185 | resolve(); |
162 | 186 | } else { |
| 187 | + console.warn('[Auto-Merge Dependabot PRs] Username validation failed:', response.responseText); |
163 | 188 | reject(new Error(`GitHub username validation failed: ${response.responseText}`)); |
164 | 189 | } |
165 | 190 | }, |
166 | 191 | onerror: function (error) { |
| 192 | + console.error('[Auto-Merge Dependabot PRs] Username validation error:', error); |
167 | 193 | reject(error); |
168 | 194 | }, |
169 | 195 | }); |
|
0 commit comments