Skip to content

Instantly share code, notes, and snippets.

@X3msnake
Forked from GuimDev/export.js
Last active September 6, 2019 10:41
Show Gist options
  • Save X3msnake/8cbd56cf7f981a38e4451ae04754ed97 to your computer and use it in GitHub Desktop.
Save X3msnake/8cbd56cf7f981a38e4451ae04754ed97 to your computer and use it in GitHub Desktop.
Export-Import GitHub Labels
/**
* 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(),
description: element.getAttribute("aria-label"),
// 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))
/**
* 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": "broken file format",
"description": null,
"color": "d93f0b"
},
{
"name": "bug",
"description": "For confirmed and presumed bugs",
"color": "b60205"
},
{
"name": "downloadable resources",
"description": "When a Issue refers to external downloadable resources",
"color": "1d76db"
},
{
"name": "duplicate",
"description": "For duplicate issues - tag and close them and referencing the official #issue",
"color": "787575"
},
{
"name": "easy",
"description": "Info for the code devs for a quick list of Easy or Fast to implement code upgrades",
"color": "ddffee"
},
{
"name": "feature request",
"description": "Tag requests for new features with this",
"color": "c2e0c6"
},
{
"name": "hard",
"description": "Info for the code devs for a quick list of Hard or Slow to implement code upgrades",
"color": "d93f0b"
},
{
"name": "help: docs",
"description": "Issue calls for documentation to be written on the wiki!",
"color": "fbca04"
},
{
"name": "help: wanted",
"description": "Tag any issue that you feel needs more human resources to be solved",
"color": "fbca04"
},
{
"name": "ideas",
"description": "Tag multiple feature requests or freetext discussion on idea sugestion for improvement or debate",
"color": "006b75"
},
{
"name": "in progress",
"description": "Feature request or bug being adressed by the team",
"color": "f7bef2"
},
{
"name": "information",
"description": "Tag issues that have know-how about the extension usage usefull for future reference",
"color": "1d76db"
},
{
"name": "investigate",
"description": "Issues that adress a hipothesis or need further insights in order to be resolved",
"color": "b35900"
},
{
"name": "medium",
"description": "Info for the code devs for a quick list of normal time to implement code upgrades",
"color": "ffa45d"
},
{
"name": "needs steps to reproduce",
"description": "Issue that needs clarification or proof of cause to be solved",
"color": "5a0a9b"
},
{
"name": "not issue",
"description": "Describes the forum thread and any thread that is conversational or does not invoke a action",
"color": "000000"
},
{
"name": "question",
"description": "Inform there is a question on how to or how is made",
"color": "ce2fa3"
},
{
"name": "support",
"description": "Issues that are related to user support",
"color": "ce2fa3"
},
{
"name": "ToDo:",
"description": "Task or list of tasks that need to be done by project colaborators",
"color": "73ddbd"
},
{
"name": "vote",
"description": "Issue that needs team voting decision",
"color": "581f89"
}
]
.forEach(function(label) {
if (!LABELS)
LABELS = [];
LABELS.push(label)
});
var LABELS;
GDV4_loop();
function GDV4_loop() {
if (LABELS[0])
addLabel(LABELS[0]);
else
return;
LABELS.shift(1);
setTimeout(GDV4_loop, 1000);
}
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('input[name="label[name]"]').value = label.name;
element.querySelector('input[name="label[description]"]').value = label.description;
element.querySelector('input[name="label[color]"]').value = '#' + label.color;
element.querySelector('button.btn-primary').click();
}
})
return flag;
}
function addNewLabel(label) {
document.querySelector('.new-label input[name="label[name]"]').value = label.name;
document.querySelector('.new-label input[name="label[description]"]').value = label.description;
document.querySelector('.new-label input[name="label[color]"]').value = '#' + label.color;
document.querySelector('.new-label button.btn-primary').disabled = false;
document.querySelector('.new-label button.btn-primary').click();
}
function addLabel(label) {
if (!updateLabel(label)) addNewLabel(label);
}
[
{
"name": "broken file format",
"description": null,
"color": "d93f0b"
},
{
"name": "bug",
"description": null,
"color": "b60205"
},
{
"name": "downloadable resources",
"description": null,
"color": "1d76db"
},
{
"name": "duplicate",
"description": null,
"color": "787575"
},
{
"name": "easy",
"description": null,
"color": "ddffee"
},
{
"name": "feature request",
"description": null,
"color": "c2e0c6"
},
{
"name": "hard",
"description": null,
"color": "d93f0b"
},
{
"name": "help: docs",
"description": null,
"color": "fbca04"
},
{
"name": "help: wanted",
"description": null,
"color": "fbca04"
},
{
"name": "ideas",
"description": null,
"color": "006b75"
},
{
"name": "in progress",
"description": null,
"color": "f7bef2"
},
{
"name": "information",
"description": null,
"color": "1d76db"
},
{
"name": "investigate",
"description": null,
"color": "b35900"
},
{
"name": "medium",
"description": null,
"color": "ffa45d"
},
{
"name": "needs steps to reproduce",
"description": null,
"color": "5a0a9b"
},
{
"name": "not issue",
"description": null,
"color": "000000"
},
{
"name": "question",
"description": null,
"color": "ce2fa3"
},
{
"name": "support",
"description": null,
"color": "ce2fa3"
},
{
"name": "ToDo:",
"description": null,
"color": "73ddbd"
},
{
"name": "vote",
"description": null,
"color": "581f89"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment