Skip to content

Instantly share code, notes, and snippets.

@MoOx
Last active February 9, 2024 22:44
Show Gist options
  • Save MoOx/93c2853fee760f42d97f to your computer and use it in GitHub Desktop.
Save MoOx/93c2853fee760f42d97f to your computer and use it in GitHub Desktop.
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".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))
@jakobe
Copy link

jakobe commented Jun 10, 2022

@jakobe I updated my code based on your comments. At the moment, looks like a good option.

Awesome 👍

@Brend-Smits
Copy link

The official GitHub CLI now includes functionality that allows you to clone labels easily from one repo to another.
Example syntax:
gh label clone org-name/repo-to-clone-from --repo org-name/repo-to-clone-to

See the documentation for more information.

@sambacha
Copy link

gh label clone org-name/repo-to-clone-from --repo org-name/repo-to-clone-to

bet

@jeffwidman
Copy link

The GitHub CLI docs also illustrate listing the labels using custom JSON output templates: https://cli.github.com/manual/gh_label_list

@adevinwild
Copy link

The official GitHub CLI now includes functionality that allows you to clone labels easily from one repo to another. Example syntax: gh label clone org-name/repo-to-clone-from --repo org-name/repo-to-clone-to

See the documentation for more information.

Thanks works well!🎉

@deffcolony
Copy link

deffcolony commented Jul 13, 2023

@jamesperrin I get the following error when i try to paste the export code in the console browser

3188:30 Uncaught TypeError: Cannot read properties of null (reading 'innerText')
    at <anonymous>:30:77
    at Array.map (<anonymous>)
    at getLabels (<anonymous>:27:27)
    at <anonymous>:79:11
    at <anonymous>:80:3
(anonymous) @ VM3188:30
getLabels @ VM3188:27
(anonymous) @ VM3188:79
(anonymous) @ VM3188:80

Do you have a fix for this?

@jamesperrin
Copy link

@jamesperrin I get the following error when i try to paste the export code in the console browser

3188:30 Uncaught TypeError: Cannot read properties of null (reading 'innerText')
    at <anonymous>:30:77
    at Array.map (<anonymous>)
    at getLabels (<anonymous>:27:27)
    at <anonymous>:79:11
    at <anonymous>:80:3
(anonymous) @ VM3188:30
getLabels @ VM3188:27
(anonymous) @ VM3188:79
(anonymous) @ VM3188:80

Do you have a fix for this?

@deffcolony I need a little more information. What is the URL for GitHub repository you tried to run the script against?

@deffcolony
Copy link

@jamesperrin I get the following error when i try to paste the export code in the console browser

3188:30 Uncaught TypeError: Cannot read properties of null (reading 'innerText')
    at <anonymous>:30:77
    at Array.map (<anonymous>)
    at getLabels (<anonymous>:27:27)
    at <anonymous>:79:11
    at <anonymous>:80:3
(anonymous) @ VM3188:30
getLabels @ VM3188:27
(anonymous) @ VM3188:79
(anonymous) @ VM3188:80

Do you have a fix for this?

@deffcolony I need a little more information. What is the URL for GitHub repository you tried to run the script against?

@jamesperrin The URL is https://github.com/deffcolony/HP-Witchcraft-and-Wizardry/labels

@jamesperrin
Copy link

jamesperrin commented Jul 17, 2023

@jamesperrin I get the following error when i try to paste the export code in the console browser

3188:30 Uncaught TypeError: Cannot read properties of null (reading 'innerText')
    at <anonymous>:30:77
    at Array.map (<anonymous>)
    at getLabels (<anonymous>:27:27)
    at <anonymous>:79:11
    at <anonymous>:80:3
(anonymous) @ VM3188:30
getLabels @ VM3188:27
(anonymous) @ VM3188:79
(anonymous) @ VM3188:80

Do you have a fix for this?

@deffcolony I need a little more information. What is the URL for GitHub repository you tried to run the script against?

@jamesperrin The URL is https://github.com/deffcolony/HP-Witchcraft-and-Wizardry/labels

@deffcolony I added validations checks for all the label properties. The issue was some label may not have a description which caused the error. You should be able to run the script without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment