Last active
August 20, 2017 17:21
-
-
Save victorzinho/dcb3fe39cfc4202139817258bf14f836 to your computer and use it in GitHub Desktop.
Create Github labels from a JSON file
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
const https = require('https'); | |
const fs = require('fs'); | |
const LABELS_FILE = 'labels.json'; | |
if (!fs.existsSync(LABELS_FILE)) { | |
console.log(LABELS_FILE + ' does not exist!'); | |
return 1; | |
} else if (process.argv.length !== 5) { | |
console.log('Usage:' + process.argv[0] + ' ' + process.argv[1] + ' <owner> <repo> <token>'); | |
return 2; | |
} | |
var options = { | |
hostname: 'api.github.com', | |
path: '/repos/' + process.argv[2] + '/' + process.argv[3] + '/labels', | |
method: 'POST', | |
headers: { | |
'Authorization': 'token ' + process.argv[4], | |
'User-Agent': 'node script' | |
} | |
}; | |
function create(name, color) { | |
var req = https.request(options, r => console.log(`Creating label ${name}...${r.statusCode}`)); | |
req.write(JSON.stringify({ name: name, color: color })); | |
req.end(); | |
} | |
var labels = JSON.parse(fs.readFileSync(LABELS_FILE, 'utf8')); | |
for(name in labels) { | |
var color = labels[name]; | |
if (typeof color !== 'string' || color.trim().length === 0) continue; | |
create(name, color); | |
} |
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
{ | |
"Priority: Critical": "ee0701", | |
"Priority: High": "ff9900", | |
"Priority: Low": "009900", | |
"Status: Ready": "c2e0c6", | |
"Status: Blocked": "b60205", | |
"Status: In Progress": "0052cc", | |
"Status: Review Needed": "eecc00", | |
"Type: Bug": "ee0701", | |
"Type: Feature": "84b6eb", | |
"Type: Question": "cc317c" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To delete all labels:
To add new labels: