Skip to content

Instantly share code, notes, and snippets.

@cvan
Forked from MoOx/index.js
Last active March 24, 2020 20:19
Show Gist options
  • Save cvan/c0601676aa2cea62fc792fa95086f791 to your computer and use it in GitHub Desktop.
Save cvan/c0601676aa2cea62fc792fa95086f791 to your computer and use it in GitHub Desktop.
Export GitHub Labels as JSON (name, description, color)
// Remixed from original source: https://gist.github.com/MoOx/93c2853fee760f42d97f
//
// 1. Go to a GitHub Labels page. (e.g., https://github.com/cssnext/cssnext/labels)
// 2. Open your Dev Tools' Console and paste this script.
// 3. Now you have a dump of your labels.
//
// P.S. The JSON output can be later imported using a tool using https://github.com/popomore/github-labels
labels = [];
Array.prototype.forEach.call(document.querySelectorAll('.Box-row a[class^=IssueLabel]'), el => {
const row = el.closest('.Box-row');
const name = el.textContent.trim();
const description = row.querySelectorAll('div')[2].textContent.trim();
const color = (el.getAttribute('style') || '').replace(/\s/g, '').toLowerCase().split(';').filter(item => item.startsWith('background-color'))[0].split(':')[1].substr(1);
labels.push({ name, description, color });
});
labels = JSON.stringify(labels, null, 2);
console.log(labels);
copy(labels); // Copy to your clipboard.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment