Skip to content

Instantly share code, notes, and snippets.

@jayu
Last active April 2, 2020 11:21
Show Gist options
  • Save jayu/b80c5f28a79a810a177d5ee97d7ab258 to your computer and use it in GitHub Desktop.
Save jayu/b80c5f28a79a810a177d5ee97d7ab258 to your computer and use it in GitHub Desktop.
Get Github labels list in super-laberer-action format
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