Skip to content

Instantly share code, notes, and snippets.

@mauris
Last active August 29, 2018 15:17
Show Gist options
  • Save mauris/25edc08c527cb072d4b2fe50243add44 to your computer and use it in GitHub Desktop.
Save mauris/25edc08c527cb072d4b2fe50243add44 to your computer and use it in GitHub Desktop.
Github Repository Labels Import / Export - Aug 2018
// Thanks to MoOx and martindafonte over at
// https://gist.github.com/MoOx/93c2853fee760f42d97f
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("aria-label"),
// using style.backgroundColor might returns "rgb(...)"
color: element.getAttribute("style")
.replace("background-color:", "")
.replace(/color:.*/,"")
.trim()
.replace(/^#/, "")
.replace(/;$/, "")
.trim(),
});
});
console.log(JSON.stringify(labels, null, 2))
var addLabel = function (label) {
document.querySelector('#label-name-.js-new-label-name-input').value = label.name;
document.querySelector('#label-description-.js-new-label-description-input').value = label.description;
document.querySelector('#label-color-.js-new-label-color-input').value = '#' + label.color;
// work around for the validation that disabled the submit button
// cannot perform a form submit as it refreshes the page.
document.querySelector('#new_label.js-create-label button[type=submit]').disabled = false;
document.querySelector('#new_label.js-create-label button[type=submit]').click();
};
var addLabels = function (labels) {
labels.forEach(addLabel);
};
// once done, refresh the page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment