|
1 | 1 | // ==UserScript== |
2 | 2 | // @name Auto-Merge Dependabot PRs |
3 | 3 | // @namespace typpi.online |
4 | | -// @version 5.5 |
| 4 | +// @version 5.6 |
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 |
|
367 | 367 | container.classList.add('pr-selection-container'); |
368 | 368 |
|
369 | 369 | const prList = document.createElement('div'); |
| 370 | + let lastChecked = null; // Track the last clicked checkbox |
| 371 | + |
370 | 372 | prs.forEach((pr) => { |
371 | 373 | const prItem = document.createElement('div'); |
372 | 374 | const checkbox = document.createElement('input'); |
|
377 | 379 | label.textContent = `Repo: ${pr.repo} - PR #${pr.number}: ${pr.title}`; |
378 | 380 | label.style = 'margin-left: 5px;'; |
379 | 381 |
|
| 382 | + // Add event listener for shift-click selection |
| 383 | + checkbox.addEventListener('click', (event) => { |
| 384 | + if (event.shiftKey && lastChecked) { |
| 385 | + const checkboxes = Array.from(prList.querySelectorAll('input[type="checkbox"]')); |
| 386 | + const start = Math.min(checkboxes.indexOf(lastChecked), checkboxes.indexOf(checkbox)); |
| 387 | + const end = Math.max(checkboxes.indexOf(lastChecked), checkboxes.indexOf(checkbox)); |
| 388 | + for (let i = start; i <= end; i++) { |
| 389 | + checkboxes[i].checked = lastChecked.checked; |
| 390 | + } |
| 391 | + } |
| 392 | + lastChecked = checkbox; // Update the last clicked checkbox |
| 393 | + }); |
| 394 | + |
380 | 395 | prItem.appendChild(checkbox); |
381 | 396 | prItem.appendChild(label); |
382 | 397 | prList.appendChild(prItem); |
|
385 | 400 | const mergeSelectedButton = document.createElement('button'); |
386 | 401 | mergeSelectedButton.textContent = 'Merge Selected PRs'; |
387 | 402 | mergeSelectedButton.addEventListener('click', async () => { |
388 | | - const selectedPRs = Array.from(prList.querySelectorAll('input:checked')).map((input) => prs.find((pr) => pr.number == input.value)); |
| 403 | + // Get all selected checkboxes |
| 404 | + const selectedCheckboxes = Array.from(prList.querySelectorAll('input[type="checkbox"]:checked')); |
| 405 | + |
| 406 | + // Map selected checkboxes to their corresponding PRs |
| 407 | + const selectedPRs = selectedCheckboxes.map((checkbox) => prs.find((pr) => pr.number == checkbox.value)); |
| 408 | + |
389 | 409 | if (selectedPRs.length > 0) { |
390 | 410 | container.innerHTML = '<div id="merge-status">Merging PRs...<br></div>'; |
391 | 411 | const groupedPRs = selectedPRs.reduce((acc, pr) => { |
|
395 | 415 | acc[pr.repo].push(pr); |
396 | 416 | return acc; |
397 | 417 | }, {}); |
| 418 | + |
| 419 | + // Merge PRs grouped by repository |
398 | 420 | for (const [repo, prs] of Object.entries(groupedPRs)) { |
399 | 421 | await mergeDependabotPRs(prs, username, repo, token); |
400 | 422 | } |
|
0 commit comments