Skip to content

Instantly share code, notes, and snippets.

@friedow
Last active July 27, 2020 10:04
Show Gist options
  • Save friedow/6b2a4034f9eda6571352f098c5ddc1b5 to your computer and use it in GitHub Desktop.
Save friedow/6b2a4034f9eda6571352f098c5ddc1b5 to your computer and use it in GitHub Desktop.
Export and Import Github Labels
[
{
"name": "Priority: Critical",
"description": "A very urgent matter.",
"color": "D7263D"
},
{
"name": "Priority: High",
"description": "High priority issue.",
"color": "F46036"
},
{
"name": "Priority: Low",
"description": "Low priority issue.",
"color": "C5D86D"
},
{
"name": "Priority: Medium",
"description": "Medium priority issue.",
"color": "0892A5"
},
{
"name": "Status: Abandoned",
"description": "This will not be worked on.",
"color": "2E294E"
},
{
"name": "Status: Available",
"description": "Something that awaits doing.",
"color": "F8C630"
},
{
"name": "Status: Blocked",
"description": "Another issue need to be finished first.",
"color": "D7263D"
},
{
"name": "Status: Done",
"description": "Something that is finished.",
"color": "60935D"
},
{
"name": "Status: In Progress",
"description": "This is currently worked on.",
"color": "C5D86D"
},
{
"name": "Status: Review Needed",
"description": "Please review the corresponding code.",
"color": "F46036"
},
{
"name": "Status: Revision Needed",
"description": "Something that needs to be overhauled.",
"color": "D7263D"
},
{
"name": "Type: Bug",
"description": "Something that is not working as it is supposed to.",
"color": "D7263D"
},
{
"name": "Type: Documentation",
"description": "A piece of missing information in the projects documentation",
"color": "F46036"
},
{
"name": "Type: Epic",
"description": "Bigger project goal that encloses multiple user stories.",
"color": "2E294E"
},
{
"name": "Type: Question",
"description": "Ask us anything :)!",
"color": "C5D86D"
},
{
"name": "Type: Story",
"description": "An improvement to the project from a user's perspective.",
"color": "0892A5"
}
]
// This script is an updated version of [MoOx export script](https://gist.github.com/MoOx/93c2853fee760f42d97f)
var labels = [];
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.getAttribute("title"),
// 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 script is an updated version of [Isaddo import script](https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4) with additions from Igelfan and NillerMedDild
[
{
"name": "Priority: Critical",
"description": "A very urgent matter.",
"color": "D7263D"
},
{
"name": "Priority: High",
"description": "High priority issue.",
"color": "F46036"
}
].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('.js-new-label-name-input').value = label.name
element.querySelector('.js-new-label-description-input').value = label.description
element.querySelector('.js-new-label-color-input').value = '#' + label.color
element.querySelector('.js-edit-label-cancel ~ .btn-primary').click()
}
})
return flag
}
function addNewLabel (label) {
document.querySelector('.js-new-label-name-input').value = label.name
document.querySelector('.js-new-label-description-input').value = label.description
document.querySelector('.js-new-label-color-input').value = '#' + label.color
document.querySelector('.js-details-target ~ .btn-primary').disabled = false
document.querySelector('.js-details-target ~ .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