Skip to content

Instantly share code, notes, and snippets.

@Bigomby
Last active October 26, 2016 14:19
Show Gist options
  • Save Bigomby/08cb112295907616631f3bd191330df6 to your computer and use it in GitHub Desktop.
Save Bigomby/08cb112295907616631f3bd191330df6 to your computer and use it in GitHub Desktop.
Add redborder's github labels
[
{
"name": "Blocked",
"color": "e99695"
},
{
"name": "bug",
"color": "fc2929"
},
{
"name": "chore",
"color": "fef2c0"
},
{
"name": "duplicate",
"color": "e6e6e6"
},
{
"name": "enhancement",
"color": "bfd4f2"
},
{
"name": "feature",
"color": "c2e0c6"
},
{
"name": "invalid",
"color": "e6e6e6"
},
{
"name": "optimization",
"color": "bfd4f2"
},
{
"name": "Ready to merge",
"color": "bfdadc"
},
{
"name": "tests",
"color": "f9d0c4"
},
{
"name": "WIP",
"color": "d4c5f9"
},
{
"name": "wontfix",
"color": "e6e6e6"
}
].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