A collage from several other gists.
To export labels from a repository:
- Go to the repository's labels page
- Run the following code in the browser's console:
var labels = [];
[].slice
.call(document.querySelectorAll(".js-label-link"))
.forEach(function (element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("title"),
// using style.backgroundColor might returns "rgb(...)"
color: element
.getAttribute("style")
.replace("background-color:", "")
.replace(/color:.*/, "")
.trim()
// github wants hex code only without # or ;
.replace(/^#/, "")
.replace(/;$/, "")
.trim(),
});
});
console.log(JSON.stringify(labels, null, 2));
To import the resulting labels to another repository:
- Go to the repository's labels page
- Delete all existing labels
- Run the following code in the browser's console:
function updateLabel(label) {
var flag = false;
[].slice
.call(document.querySelectorAll(".labels-list-item"))
.forEach(function (element) {
if (
element.querySelector(".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);
}
// The labels resulting from the export operation
[
{
name: "wip",
description: "Work in progress",
color: "a8d3da",
},
{
name: "bug",
description: "Something isn't working",
color: "ef6c57",
},
{
name: "documentation",
description: "Improvements or additions to documentation",
color: "f4eeff",
},
{
name: "duplicate",
description: "This issue or pull request already exists",
color: "383e56",
},
{
name: "enhancement",
description: "New feature or request",
color: "ffe3b0",
},
{
name: "help wanted",
description: "Extra attention is needed",
color: "aacdbe",
},
].forEach(function (label) {
addLabel(label);
});