Skip to content

Instantly share code, notes, and snippets.

@bakerboy448
Last active April 11, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bakerboy448/14ea471da15ff5f8c38d7260099ad028 to your computer and use it in GitHub Desktop.
Save bakerboy448/14ea471da15ff5f8c38d7260099ad028 to your computer and use it in GitHub Desktop.
Update GH Labels
/**
/**
* Inspired by @Isaddo original script: https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4
* Adds descriptions per @NillerMedDild https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4#gistcomment-2715349
* Updated with https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4#gistcomment-3611299
*/
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);
}
// Your labels between [ and ]
[
{
"name": "Area: API",
"description": "Issue is related to the API",
"color": "e99695"
},
{
"name": "Type: Support.",
"description": "(silent) Issue is a support request. Bot WILL NOT auto close and give a message.",
"color": "b91de0"
}
]
.forEach(function (label) {
addLabel(label);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment