Skip to content

Instantly share code, notes, and snippets.

@bitst0rm
Created September 6, 2024 00:25
Show Gist options
  • Save bitst0rm/85413dfb112e1fb744779e0bfbe82da3 to your computer and use it in GitHub Desktop.
Save bitst0rm/85413dfb112e1fb744779e0bfbe82da3 to your computer and use it in GitHub Desktop.
Import Github Labels via console commands
/* Import GitHub labels
* @ref: https://gist.github.com/Isaddo/7efebcb673a0957b9c6f07cd14826ea4
*
* @see: https://gist.github.com/bitst0rm
* export-github-labels.js
* import-github-labels.js
* delete-github-labels.js
*
* To use:
* 1. Go to the labels page of your repository (e.g., https://github.com/user/repo/labels).
* 2. Paste this script into your browser's JavaScript console.
* 3. Press Enter!
*
* This script will:
* - import predefined labels into your GitHub repository.
* - update existing labels if they match the name of a label in the script.
* - create new labels if they don't already exist in the repository.
*/
(function() {
// Paste your labels here
var labels = [{
"name": "bug",
"description": "Something isn't working",
"color": "#d73a4a"
},
{
"name": "conflict",
"description": "This leads to conflict among roosters",
"color": "#d93f0b"
},
{
"name": "documentation",
"description": "Improvements or additions to documentation",
"color": "#0075ca"
},
{
"name": "duplicate",
"description": "This issue or pull request already exists",
"color": "#cfd3d7"
},
{
"name": "enhancement",
"description": "New feature or request",
"color": "#a2eeef"
},
{
"name": "๐Ÿ’ enhancement",
"description": "High priority: this has more power than all presidents of the United States together",
"color": "#f9d0c4"
},
{
"name": "๐Ÿ† enlargement",
"description": "Low priority: this has a power of a AAA battery, enough to send Chuck Norris to the mond and back",
"color": "#d4c5f9"
},
{
"name": "external",
"description": "This issue is not related to this project",
"color": "#a89967"
},
{
"name": "feedback required",
"description": "Confirmation or additional details are requested",
"color": "#fbca04"
},
{
"name": "good first issue",
"description": "Good for newcomers",
"color": "#7057ff"
},
{
"name": "help wanted",
"description": "Extra attention is needed",
"color": "#008672"
},
{
"name": "in progress",
"description": "Work is currently underway",
"color": "#bede0c"
},
{
"name": "info",
"description": "This is for informational purposes",
"color": "#41ada6"
},
{
"name": "invalid",
"description": "This doesn't seem right",
"color": "#e4e669"
},
{
"name": "offtopic",
"description": "Talk about your lovesickness and favorist pr0n movies",
"color": "#1d76db"
},
{
"name": "question",
"description": "Further information is requested",
"color": "#d876e3"
},
{
"name": "wontfix",
"description": "This will not be worked on",
"color": "#ffffff"
}
];
labels.forEach(function(label) {
addLabel(label);
});
function updateLabel(label) {
var labelsListItems = document.querySelectorAll(".js-labels-list-item");
var updated = false;
var itemToUpdate = Array.from(labelsListItems).find(function(element) {
return element.querySelector(".js-label-link").textContent.trim() === label.name;
});
if (itemToUpdate) {
updated = true;
var editButton = itemToUpdate.querySelector(".js-edit-label");
var nameInput = itemToUpdate.querySelector(".js-new-label-name-input");
var descriptionInput = itemToUpdate.querySelector(".js-new-label-description-input");
var colorInput = itemToUpdate.querySelector(".js-new-label-color-input");
var cancelButton = itemToUpdate.querySelector(".js-edit-label-cancel ~ .btn-primary");
editButton.click();
nameInput.value = label.name;
descriptionInput.value = label.description;
colorInput.value = label.color;
cancelButton.click();
}
return updated;
}
function addNewLabel(label) {
var nameInput = document.querySelector(".js-new-label-name-input");
var descriptionInput = document.querySelector(".js-new-label-description-input");
var colorInput = document.querySelector(".js-new-label-color-input");
var saveButton = document.querySelector(".js-details-target ~ .btn-primary");
nameInput.value = label.name;
descriptionInput.value = label.description;
colorInput.value = label.color;
saveButton.disabled = false;
saveButton.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