Last active
April 2, 2020 11:21
-
-
Save jayu/b80c5f28a79a810a177d5ee97d7ab258 to your computer and use it in GitHub Desktop.
Get Github labels list in super-laberer-action format
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
var labels = []; | |
[].slice.call(document.querySelectorAll(".js-label-link")) | |
.forEach(function (element) { | |
labels.push({ | |
name: element.textContent.trim(), | |
description: element.getAttribute("title") || "", | |
// using style.backgroundColor might returns "rgb(...)" | |
colour: element.getAttribute("style") | |
.replace("background-color:", "") | |
.replace(/color:.*/, "") | |
.trim() | |
// github wants hex code only without # or ; | |
.replace(/^#/, "") | |
.replace(/;$/, "") | |
.trim(), | |
}) | |
}) | |
var stripName = (name) => name | |
.trim() | |
.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF]|\uFE0F)/g, '') | |
.trim() | |
.replace(/\:|\s/g, '\-') | |
.replace(/(\-)+/g, '\-') | |
.replace(/^(\-)+/g, '') | |
.replace(/(\-)+\s?$/g, '') | |
labels = labels.reduce((labels, current) => ({ | |
...labels, | |
[stripName(current.name)]: current | |
}), {}) | |
console.log(JSON.stringify(labels, null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment