Last active
August 29, 2018 15:17
-
-
Save mauris/25edc08c527cb072d4b2fe50243add44 to your computer and use it in GitHub Desktop.
Github Repository Labels Import / Export - Aug 2018
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
// 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)) |
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
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