-
Star
(155)
You must be signed in to star a gist -
Fork
(33)
You must be signed in to fork a gist
-
-
Save MoOx/93c2853fee760f42d97f to your computer and use it in GitHub Desktop.
// 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)) |
Update June 2022: As far as I can see the description no longer exists as title
on the label element itself.
Though it might be brittle to rely on the DOM structure of the labels page, this is my fix getting the description from the column after the label itself:
...
description: jsLabel.parentElement.nextElementSibling.firstElementChild.innerText.trim(),
...
@jakobe I updated my code based on your comments. At the moment, looks like a good option.
@jakobe I updated my code based on your comments. At the moment, looks like a good option.
Awesome 👍
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.
gh label clone org-name/repo-to-clone-from --repo org-name/repo-to-clone-to
bet
The GitHub CLI docs also illustrate listing the labels using custom JSON output templates: https://cli.github.com/manual/gh_label_list
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!🎉
@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 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:80Do 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 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:80Do 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 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:80Do 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.
tl;dr gh label clone src-org/src_repo --repo dest-org/dest_org
If you're coming by this thread in 2024 or later, I highly recommend seeing the official GitHub CLI [1].
-
Install this for your repository : https://probot.github.io/apps/settings/
-
Go to any repo from where you want to extract the labels
e.g https://github.com/maheshj01/pastelog/issues/labels -
paste the below script in the chrome console
below script extracts the labels and generates output in yml format
var labels = [];
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
function rgba2hex(rgba) {
rgba = rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*\d+\.*\d+)?\)$/);
return hex(rgba[1]) + hex(rgba[2]) + hex(rgba[3]);
}
[].slice.call(document.querySelectorAll(".js-label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
description: element.parentElement.nextElementSibling.firstElementChild.innerText.trim(),
// Extract color using rgba2hex function
color: rgba2hex(window.getComputedStyle(element).getPropertyValue("background-color")),
})
});
let yamlOutput = labels.map(label =>
`- name: ${label.name}\n description: ${label.description}\n color: ${label.color}`
).join("\n");
console.log(yamlOutput);
- copy the output and go to your repository and create
.github/settings.yaml
and paste the labels copied in step 3
sample settings.yml
for all configurations for this settings refer link in step 1
repository:
name: repo-name
description: repo-description
homepage: https://example.com
topics: nextjs, tailwindcss, typescript, chrome-extension
private: true
labels:
- name: bug
description: Something isn't working
color: d73a4a
- name: documentation
description: Improvements or additions to documentation
color: 0075ca
- name: duplicate
description: This issue or pull request already exists
color: cfd3d7
milestones:
- title: milestone-title
description: milestone-description
state: open
Here are my updates for exporting and importing issues labels.
It should be cross browser compatible except for IE which is pretty much dead.
github-labels-export.js
https://gist.github.com/jamesperrin/c2bf6d32fbb8142682f6107e561b664d
github-labels-import.js
https://gist.github.com/jamesperrin/d811fadea2bd199ecf98195d96513afd