Created
September 6, 2024 00:26
-
-
Save bitst0rm/0c81b4ad041cf57ede5ed857b9c68f06 to your computer and use it in GitHub Desktop.
Delete Github Labels via console commands
This file contains 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
/* Delete GitHub labels | |
* @ref: https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4 | |
* | |
* @see: https://gist.github.com/bitst0rm | |
* export-github-labels.js | |
* import-github-labels.js | |
* delete-github-labels.js | |
* | |
* To use: | |
* 1. Go to the labels page of your repository (e.g., https://github.com/user/repo/labels). | |
* 2. Paste this script into your browser's JavaScript console. | |
* 3. Press Enter! | |
* | |
* This script will: | |
* - locate all labels on the labels page of your GitHub repository. | |
* - remove the confirmation requirement for deleting each label. | |
* - submit the deletion forms for each label asynchronously. | |
* - refresh the list of labels after each deletion to ensure all labels are removed. | |
*/ | |
(function() { | |
function deleteAllLabels() { | |
var deleteForms = document.querySelectorAll(".js-delete-label"); | |
function submitForm(form) { | |
return new Promise(function(resolve) { | |
form.submit(); | |
// Set up an interval to check if the page is still loading | |
var checkPageLoad = setInterval(function() { | |
if (document.readyState === 'complete') { | |
clearInterval(checkPageLoad); | |
resolve(); | |
} | |
}, 100); // Check every 100ms | |
}); | |
} | |
// Iterate over each form and handle the deletion | |
(async function() { | |
for (var i = 0; i < deleteForms.length; i++) { | |
var form = deleteForms[i]; | |
var deleteButton = form.querySelector("button[type='submit']"); | |
// Remove the data-confirm attribute | |
deleteButton.removeAttribute("data-confirm"); | |
// Submit the form and wait for it to complete | |
await submitForm(form); | |
// Refresh the list of forms after each deletion | |
deleteForms = document.querySelectorAll(".js-delete-label"); | |
} | |
})(); | |
} | |
deleteAllLabels() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment