Skip to content

Instantly share code, notes, and snippets.

@sarpavci
Last active June 23, 2023 15:14
Show Gist options
  • Select an option

  • Save sarpavci/11b5fcc3aac904ad31f32979921aafea to your computer and use it in GitHub Desktop.

Select an option

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")`
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