Last active
April 11, 2019 21:45
-
-
Save vict0rsch/188a60f1e87a68844e41082583df64c4 to your computer and use it in GitHub Desktop.
Get all labels + colors + description on your repository's `labels` section into a Project-Bot compatible settings.yml file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just run this whole script in your browser's console on the appropriate webpage | |
// For instance on https://github.com/facebook/create-react-app/labels | |
// 1 | |
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(), | |
description: `"${element.parentElement.nextElementSibling.textContent.trim()}"` | |
}) | |
}) | |
// 2 | |
const out = "labels:\n" + labels.map( | |
(l, i) => ` - name: ${l.name}\n color: ${l.color}\n description: ${l.description || '""'}\n` | |
).join("\n") | |
// 3 | |
function saveYML(text, filename) { | |
const blob = new Blob([text], { type: 'text/plain' }); | |
const e = document.createEvent('MouseEvents'); | |
const a = document.createElement('a'); | |
a.download = filename; | |
a.href = window.URL.createObjectURL(blob); | |
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':'); | |
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
a.dispatchEvent(e); | |
} | |
saveYML(out, "settings.yml") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output from https://github.com/facebook/create-react-app/labels