Skip to content

Instantly share code, notes, and snippets.

@hendrikeng
Forked from Isaddo/import-github-labels.js
Created May 15, 2017 10:50
Show Gist options
  • Save hendrikeng/14d78fdc73dead50eacafade4e731b9c to your computer and use it in GitHub Desktop.
Save hendrikeng/14d78fdc73dead50eacafade4e731b9c to your computer and use it in GitHub Desktop.
import github labels via console command
/*
Go on your labels page (https://github.com/user/repo/labels)
Edit the following label array
or
Use this snippet to export github labels (https://gist.github.com/MoOx/93c2853fee760f42d97f)
and replace it
Paste this script in your console
Press Enter!!
*/
[
{
"name": "Bug",
"color": "b60205"
},
{
"name": "Dublicate",
"color": "cecece"
},
{
"name": "Enhancement",
"color": "1d76db"
},
{
"name": "Feature",
"color": "0e8a16"
},
{
"name": "In Progress",
"color": "006b75"
},
{
"name": "Invalid",
"color": "cecece"
},
{
"name": "Prio: High",
"color": "f9d0c4"
},
{
"name": "Prio: Low",
"color": "fef2c0"
},
{
"name": "Question",
"color": "d4c5f9"
},
{
"name": "Wontfix",
"color": "cecece"
}
].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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment