-
-
Save DeathGOD7/a7eb12dd1b6749212d4703dec74ad054 to your computer and use it in GitHub Desktop.
Export-import Github repo labels
This file contains 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
// 1. Go on you labels page: | |
// eg.: https://github.com/EbookFoundation/free-programming-books/labels | |
// | |
// 2. Paste this script in your console / save as browser bookmarklet, and then execute it | |
// 3. Copy the output / download files and now you can import it using https://github.com/popomore/github-labels ! | |
// | |
// How to bookmark: https://gist.github.com/caseywatts/c0cec1f89ccdb8b469b1 | |
(function(undefined) { | |
var reposlug; | |
try { | |
window.location.hostname.indexOf("github.com") != -1 && (reposlug = window.location.pathname.match(/([^\/]+\/[^\/]+)\/labels/i)[1].toLowerCase().replace(/\//ig, "__")); | |
} catch(e) { } | |
if (!reposlug) { | |
throw "It seems that you are not in a github.com repo labels page: " + window.location; | |
} | |
var labels = [].slice.call(document.querySelectorAll(".js-label-link")).map(function(el) { | |
var styles = window.getComputedStyle(el); | |
return { | |
name: el.textContent.trim(), /* required */ | |
description: el.getAttribute("title") || el.getAttribute("aria-label") || null, /* optional */ | |
color: rgba2hex(styles.getPropertyValue("background-color")), /* required */ | |
}; | |
}); | |
var json = JSON.stringify(labels, null, 2), yaml = labels2yml(labels); | |
var exts = (window.prompt("Choice download formats to save " +labels.length+ " labels.\n\n Options: json,yml,yaml\n\nCancel or leave empty to ignore.", "json,yml")||"").split(/\s*,\s*/); | |
(exts.includes("json")) && save(reposlug+"__labels.json", "application/json", json); | |
(exts.includes("yaml") || exts.includes("yml")) && save(reposlug+"__labels.yml", "application/yaml", yaml); | |
return { | |
labels: labels, | |
jsonText: json, | |
yamlText: yaml, | |
}; | |
function hex(x) { | |
return ("0" + parseInt(x).toString(16)).slice(-2); | |
} | |
function rgba2hex(rgba) { | |
rgba = rgba.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*\d+\.*\d+)?\)$/); | |
return rgba.slice(1,4).reduce(function(s, x){ return s + hex(x); }, ""); | |
} | |
function save(filename, type, content) { | |
const blob = new Blob([content], { type: type }); | |
const e = document.createEvent("MouseEvents"); | |
const a = document.createElement("a"); | |
a.download = filename; | |
a.href = window.URL.createObjectURL(blob); | |
a.dataset.downloadurl = [type, 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); | |
} | |
function labels2yml(labels) { | |
return labels.reduce(function(s, l){ | |
return s +" - name: \"" +(l.name)+ "\"\n description: \"" +(l.description||"")+ "\"\n color: \"" +(l.color)+ "\"\n"; | |
}, "labels:\n"); | |
} | |
}()); |
A pleasure. Thanks for mention ❤❤❤
@davorpa Well, it's thanks to you for making exporter from js and without installing any software or packages and adding tokens (sharing tokens is always scary) in PC to get them.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also to easily import and export things.
Use @davorpa code mentioned here. (direct link)
And for importing just install "Settings" app (link) by probot and make this file :
.github/settings.yml
Happy importing. And thanks to @davorpa for both json and yml / yaml file saver.