Skip to content

Instantly share code, notes, and snippets.

@fupslot
Created October 19, 2017 10:26
Show Gist options
  • Save fupslot/8236c1c82d201dea36a75b5c55ca0b4a to your computer and use it in GitHub Desktop.
Save fupslot/8236c1c82d201dea36a75b5c55ca0b4a to your computer and use it in GitHub Desktop.
[
{
"name": "b2c",
"color": "bfd4f2"
},
{
"name": "b2b",
"color": "bfd4f2"
},
{
"name": "api",
"color": "bfd4f2"
},
{
"name": "interprise",
"color": "bfd4f2"
},
{
"name": "bug",
"color": "ee3f46"
},
{
"name": "security",
"color": "ee3f46"
},
{
"name": "production",
"color": "ee3f46"
},
{
"name": "dev",
"color": "fad8c7"
},
{
"name": "staging",
"color": "fad8c7"
},
{
"name": "discussion",
"color": "cc317c"
},
{
"name": "question",
"color": "cc317c"
},
{
"name": "feature",
"color": "91ca55"
},
{
"name": "in progress",
"color": "fbca04"
},
{
"name": "watchlist",
"color": "fbca04"
},
{
"name": "invalid",
"color": "d2dae1"
},
{
"name": "wontfix",
"color": "d2dae1"
},
{
"name": "duplicate",
"color": "d2dae1"
},
{
"name": "on hold",
"color": "d2dae1"
},
{
"name": "design",
"color": "ffc274"
},
{
"name": "ux",
"color": "ffc274"
}
].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-name-').value = label.name
document.querySelector('.new-label input#label-color-').value = '#' + label.color
document.querySelector('.new-label .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