Skip to content

Instantly share code, notes, and snippets.

@dysfunc
Last active February 20, 2021 17:58
Show Gist options
  • Save dysfunc/882d3d4bae265c9df38ce6e7ce65f9d5 to your computer and use it in GitHub Desktop.
Save dysfunc/882d3d4bae265c9df38ce6e7ce65f9d5 to your computer and use it in GitHub Desktop.
Export & Import GitHub Labels
  • Visit the labels page you want to copy
  • Open the Developer Console
  • Paste this snippet and hit enter
const labels = [];
const list = [].slice.call(document.querySelectorAll(".js-label-link"));

list.forEach((element) => {
  labels.push({
    name: element.textContent.trim(),
    description: element.getAttribute("title"),
    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))

You should see an output for all of the labels listed.

Now you need to:

  • Assign the output Array to a const names labels (const labels = [...]);
  • Visit the new labels page where you want to import the labels
  • Click the "New Label" button
  • Open Developer Console
  • Open the Developer Console
  • Paste this snippet and hit enter
const name = document.getElementById('label-name-');
const description = document.getElementById('label-description-');
const color = document.getElementById('label-color-');
const submit = document.querySelector('.js-label-form .btn.btn-primary');

labels.forEach((label) => addNewLabel(label));

function addNewLabel (label) {
  name.value = label.name;
  description.value = label.description;
  color.value = '#' + label.color;
  submit.removeAttribute('disabled');
  submit.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment