Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get all labels + colors + description on your repository's `labels` section into a Project-Bot compatible settings.yml file
// 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")
@vict0rsch
Copy link
Author

vict0rsch commented Apr 11, 2019

  1. Get labels as a list of objects with fields name color and description
  2. Create a yml-compatible string out
  3. Download out as a settings.yml file

Most work from https://gist.github.com/MoOx/93c2853fee760f42d97f

@vict0rsch
Copy link
Author

vict0rsch commented Apr 11, 2019

Output from https://github.com/facebook/create-react-app/labels

labels:
  - name: "CLA Signed"
    color: 009900
    description: ""

  - name: "contributions: claimed"
    color: d93f0b
    description: ""

  - name: "contributions: up for grabs!"
    color: 128A0C
    description: ""

  - name: "difficulty: complex"
    color: f9d0c4
    description: ""

  - name: "difficulty: impossible"
    color: e99695
    description: ""

  - name: "difficulty: medium"
    color: fef2c0
    description: ""

  - name: "difficulty: starter"
    color: c5def5
    description: ""

  - name: "good first issue"
    color: 128A0C
    description: ""

  - name: "hacktoberfest"
    color: ff625f
    description: ""

  - name: "issue: announcement"
    color: 5319e7
    description: ""

  - name: "issue: bug"
    color: ee0701
    description: ""

  - name: "issue: install problem"
    color: e5aa4b
    description: ""

  - name: "issue: needs investigation"
    color: d106e8
    description: ""

  - name: "issue: proposal"
    color: fbca04
    description: ""

  - name: "issue: question > PWA"
    color: c5def5
    description: ""

  - name: "issue: question"
    color: 006b75
    description: ""

  - name: "issue: typescript"
    color: 007acc
    description: ""

  - name: "priority: low (ignored issue template)"
    color: d4c5f9
    description: ""

  - name: "priority: low (needs more information)"
    color: d4c5f9
    description: ""

  - name: "stale"
    color: f4d37f
    description: ""

  - name: "tag: breaking change"
    color: e11d21
    description: ""

  - name: "tag: bug fix"
    color: fbca04
    description: ""

  - name: "tag: documentation"
    color: 006b75
    description: ""

  - name: "tag: enhancement"
    color: 1d76db
    description: ""

  - name: "tag: internal"
    color: bfdadc
    description: ""

  - name: "tag: new feature"
    color: 0e8a16
    description: ""

  - name: "tag: underlying tools"
    color: d93f0b
    description: ""

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