Last active
April 8, 2020 15:49
-
-
Save turtlepod/353ee764592d0dd357cb86f7830e8096 to your computer and use it in GitHub Desktop.
Export-Import GitHub Labels
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
/** | |
* 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(), | |
// 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)) | |
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
/** | |
* 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", | |
"color": "eb6420" | |
}, | |
{ | |
"name": "feature", | |
"color": "0e8a16" | |
}, | |
{ | |
"name": "hotfix", | |
"color": "e11d21" | |
} | |
] | |
.forEach(function(label) { | |
addLabel(label) | |
}) | |
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('.label-edit-name').value = label.name | |
element.querySelector('.color-editor-input').value = '#' + label.color | |
element.querySelector('.new-label-actions .btn-primary').click() | |
} | |
}) | |
return flag | |
} | |
function addNewLabel (label) { | |
document.querySelector('.new-label input#label-').value = label.name | |
document.querySelector('.new-label input#edit-label-color-new').value = '#' + label.color | |
document.querySelector('.new-label-actions .btn-primary').click() | |
} | |
function addLabel (label) { | |
if (!updateLabel(label)) addNewLabel(label) | |
} |
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
[ | |
{ | |
"name": "bug", | |
"color": "ee0701" | |
}, | |
{ | |
"name": "duplicate", | |
"color": "cccccc" | |
}, | |
{ | |
"name": "enhancement", | |
"color": "84b6eb" | |
}, | |
{ | |
"name": "help wanted", | |
"color": "128A0C" | |
}, | |
{ | |
"name": "invalid", | |
"color": "e6e6e6" | |
}, | |
{ | |
"name": "question", | |
"color": "cc317c" | |
}, | |
{ | |
"name": "wontfix", | |
"color": "ffffff" | |
} | |
] |
You forgot the description : description: element.getAttribute("aria-label"),
: https://gist.github.com/GuimDev/b29673641c85ed83526163f6aa290008
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks to @MoOx and @Isaddo for the code :)