Skip to content

Instantly share code, notes, and snippets.

@rafiamafia
Last active May 27, 2022 00:29
Show Gist options
  • Save rafiamafia/157936c6eaa13de3a2a846135b5bcab5 to your computer and use it in GitHub Desktop.
Save rafiamafia/157936c6eaa13de3a2a846135b5bcab5 to your computer and use it in GitHub Desktop.

Labels:

How to copy Labels from source repo to dest repo

  1. Open the "Labels" tab in your GitHub source repo and paste this in the browser js console:
var labels = [];
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function(element) {
  labels.push({
    name: element.textContent.trim(),
    // 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))
  1. Copy the labels and create a conf.json file
[{
  "name": "Approved",
  "color": "62d153"
}, {
  "name": "Ready for Review",
  "color": "FF8C00"
}, {
  "name": "Under Development",
  "color": "cfd3d7"
}, {
  "name": "Under Review",
  "color": "e4e669"
}, {
  "name": "Under Testing",
  "color": "bfd4f2"
}]
  1. Install npm package
npm install github-labels -g
  1. Import labels to desired repo
labels -c conf.json -h github.company-dns -p /api/v3 -t <enter-token> org/repo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment