- This script allows export, import, update and delete of GitHub Labels
- Adopted from Isaddo's gist with some tweaks for 2020
- Included a
delete
script too
- Go to the source repository's labels page
- Open up the browser console
- Copy and paste the following script & copy its output
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))
- Go to destination repository's labels page
- Open browser console
- Copy and paste the following script
(Note: This script will delete all labels)[] .slice .call(document.querySelectorAll(".js-labels-list-item")) .forEach(function(element) { var button = element.querySelector('.js-delete-label').querySelector('button') button.removeAttribute('data-confirm') button.click() })
- Go the destination repository's labels page
- Open up the browser console
- Paste the output from the previous section
- Copy and paste the following script to the same last line of the previus step
(The script below will import new labels or automatically update pre-existing labels).forEach(function(label) { addLabel(label) }) function updateLabel (label) { var flag = false; [] .slice .call(document.querySelectorAll(".js-labels-list-item")) .forEach(function(element) { if (element.querySelector('.js-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) }