Skip to content

Instantly share code, notes, and snippets.

@gptkrsh
Last active January 13, 2023 10:47
Show Gist options
  • Save gptkrsh/f723e675cfe815b078cbfe963dd49076 to your computer and use it in GitHub Desktop.
Save gptkrsh/f723e675cfe815b078cbfe963dd49076 to your computer and use it in GitHub Desktop.
@krshoss labeller
document.querySelectorAll('.js-delete-label').forEach(form => form.querySelector('button').click())
const labels = (await ((await fetch('https://github.com/krshoss/repo-labels/raw/main/labels.json')).json()))
function createLabel(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 updateLabel(label) {
let updatedLabel = false;
[].slice
.call(document.querySelectorAll(".js-labels-list-item"))
.forEach((element) => {
if (
element.querySelector(".js-label-link").textContent.trim() ===
label.name
) {
updatedLabel = 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 updatedLabel;
}
function createOrUpdate(label) {
if (!updateLabel(label)) {
createLabel(label);
}
}
labels.forEach((label) => createOrUpdate(label));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment