Last active
June 23, 2023 15:14
-
-
Save sarpavci/11b5fcc3aac904ad31f32979921aafea to your computer and use it in GitHub Desktop.
go to stale branch list page then run this script in devtools console 👍 `deleteBranches("org", "repo")`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function deleteBranches(org, repo) { | |
| await Promise.allSettled( | |
| Array | |
| .from(document.getElementsByClassName('js-branch-delete-button')) | |
| .map((elm) => new Promise((resolve, reject) => { | |
| const branchName = elm.getAttribute('title').replace('Delete ', ''); | |
| const deleteUrl = `https://github.com/${org}/${repo}/branches/${branchName}`; | |
| const authenticityToken = elm.closest('form').querySelector('[name="authenticity_token"]').value; | |
| const method = 'POST'; | |
| const body = new FormData(); | |
| body.append('_method', 'delete'); | |
| body.append('authenticity_token', authenticityToken); | |
| const headers = headers: { 'x-requested-with': 'XMLHttpRequest' }; | |
| return fetch(deleteUrl, { headers, body, method }) | |
| .then(() => { | |
| elm.closest('.Box-row.position-relative').remove(); | |
| return resolve(); | |
| }).catch(reject); | |
| })) | |
| ).then((results) => { | |
| document.querySelector('.pagination a').click(); | |
| return setTimeout(() => deleteBranches(org, repo), 5000); | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment