Created
January 6, 2022 20:22
-
-
Save AHilyard/5babebe06c30a48e07d949053e00bd5c to your computer and use it in GitHub Desktop.
Import 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
/* | |
This script will import Github labels from an array. | |
Optionally, existing labels can be removed prior to import. | |
Instructions: | |
Go to the labels page for the repo you'd like to import to (https://github.com/user/repo/labels) | |
Run the labels exporter script first, if you haven't. (https://gist.github.com/AHilyard/a5b9376d0326fd658a8064d5569791a4) | |
Modify this script by pasting your labels in where directed, | |
and optionally changing the "removeExisting" variable to true. | |
Press Enter | |
Done! | |
*/ | |
function updateLabel(label) { | |
var flag = false; | |
[].slice | |
.call(document.querySelectorAll(".js-labels-list-item")) | |
.forEach(function (element) { | |
if ( | |
element.querySelector(".js-label-link").textContent.trim() === label.name | |
) { | |
flag = true; | |
element.querySelector(".js-edit-label").click(); | |
element.querySelector(".js-new-label-name-input").value = label.name; | |
element.querySelector(".js-new-label-description-input").value = label.description; | |
element.querySelector(".js-new-label-color-input").value = "#" + label.color; | |
element.querySelector(".js-edit-label-cancel ~ .btn-primary").click(); | |
} | |
}); | |
return flag; | |
} | |
function addNewLabel(label) { | |
document.querySelector(".js-new-label-name-input").value = label.name; | |
document.querySelector(".js-new-label-description-input").value = label.description; | |
document.querySelector(".js-new-label-color-input").value = "#" + label.color; | |
document.querySelector(".js-details-target ~ .btn-primary").disabled = false; | |
document.querySelector(".js-details-target ~ .btn-primary").click(); | |
} | |
function addLabel(label) { | |
if (!updateLabel(label)) | |
{ | |
addNewLabel(label); | |
} | |
} | |
// Change this to true to remove all existing labels first. | |
var removeExisting = false; | |
// Remove all pre-existing labels. | |
if (removeExisting) | |
{ | |
[].slice.call(document.querySelectorAll(".js-delete-label")).forEach(function (element) { | |
// Remove the confirmation dialogue first. | |
element.querySelector(".btn-link").removeAttribute("data-confirm"); | |
element.querySelector(".btn-link").click(); | |
}); | |
} | |
// Paste your labels here | |
[] | |
.forEach(function (label) { | |
addLabel(label); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment