Skip to content

Instantly share code, notes, and snippets.

@GuimDev
Forked from turtlepod/export.js
Last active July 9, 2019 17:40
Show Gist options
  • Save GuimDev/b29673641c85ed83526163f6aa290008 to your computer and use it in GitHub Desktop.
Save GuimDev/b29673641c85ed83526163f6aa290008 to your computer and use it in GitHub Desktop.
Export-Import GitHub Labels
/**
* Export Github Labels
****************************************************
*
* FIREFOX STEP BY STEP:
* 1. Open the labels manage page e.g github.com/user/repo/lebels
* 2. Open Scratch Pad (SHIFT + F4)
* 3. Paste the code below and run
* 4. Inspect Element > Console ( To read console log)
* 5. Copy it the console.log results
*
* @link https://gist.github.com/turtlepod/353ee764592d0dd357cb86f7830e8096/
*
* @link https://gist.github.com/MoOx/93c2853fee760f42d97f
* @link https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4
**/
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()
// github wants hex code only without # or ;
.replace(/^#/, "")
.replace(/;$/, "")
.trim(),
})
})
console.log(JSON.stringify(labels, null, 2))
/**
* Import Github Labels
****************************************************
*
* FIREFOX STEP BY STEP:
* 1. Open the labels manage page e.g github.com/user/repo/lebels
* 2. Open Scratch Pad (SHIFT + F4)
* 3. Paste the code below
* 4. Replace the labels array with your own labels data from export.js
* 5. Run it, and see the new labels
*
* @link https://gist.github.com/turtlepod/353ee764592d0dd357cb86f7830e8096/
*
* @link https://gist.github.com/MoOx/93c2853fee760f42d97f
* @link https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4
**/
[
{
"name": "bugfix",
"description": "bugfix",
"color": "eb6420"
},
{
"name": "feature",
"description": "feature",
"color": "0e8a16"
},
{
"name": "hotfix",
"description": "hotfix",
"color": "e11d21"
}
]
.forEach(function(label) {
if (!LABELS)
LABELS = [];
LABELS.push(label)
});
var LABELS;
GDV4_loop();
function GDV4_loop() {
if (LABELS[0])
addLabel(LABELS[0]);
else
return;
LABELS.shift(1);
setTimeout(GDV4_loop, 1000);
}
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('input[name="label[name]"]').value = label.name;
element.querySelector('input[name="label[description]"]').value = label.description;
element.querySelector('input[name="label[color]"]').value = '#' + label.color;
element.querySelector('button.btn-primary').click();
}
})
return flag;
}
function addNewLabel(label) {
document.querySelector('.new-label input[name="label[name]"]').value = label.name;
document.querySelector('.new-label input[name="label[description]"]').value = label.description;
document.querySelector('.new-label input[name="label[color]"]').value = '#' + label.color;
document.querySelector('.new-label button.btn-primary').disabled = false;
document.querySelector('.new-label button.btn-primary').click();
}
function addLabel(label) {
if (!updateLabel(label)) addNewLabel(label);
}
[
{
"name": "bug",
"description": "1234",
"color": "ee0701"
},
{
"name": "duplicate",
"description": "1234",
"color": "cccccc"
},
{
"name": "enhancement",
"description": "1234",
"color": "84b6eb"
},
{
"name": "help wanted",
"description": "1234",
"color": "128A0C"
},
{
"name": "invalid",
"description": "1234",
"color": "e6e6e6"
},
{
"name": "question",
"description": "1234",
"color": "cc317c"
},
{
"name": "wontfix",
"description": "1234",
"color": "ffffff"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment