Last active
February 7, 2017 15:49
-
-
Save qubyte/3496ca3f4a20a9edde8e to your computer and use it in GitHub Desktop.
Replace labels for a repo with standard set.
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
var token = '<insert token>'; | |
var owner = '<insert owner>'; | |
var repo = '<insert repo>'; | |
var newLabels = [ | |
{color: 'e11d21', name: 'Blocked'}, | |
{color: '000000', name: 'Do Not Merge!'}, | |
{color: 'eb6420', name: 'QA Defect'}, | |
{color: '5319e7', name: 'Waiting for QA'}, | |
{color: '009800', name: 'Waiting for Review'}, | |
{color: 'ff3399', name: 'Waiting for Submitter'}, | |
{color: 'bada55', name: 'Waiting for UX'} | |
]; | |
var labelsUrl = `https://api.github.com/repos/${owner}/${repo}/labels`; | |
function makeHeaders(extras) { | |
return Object.assign({}, {'user-agent': 'node', Authorization: `token ${token}`}, extras); | |
} | |
function getOldLabels() { | |
var requestOptions = { | |
headers: makeHeaders({Accept: 'application/json'}) | |
}; | |
return fetch(labelsUrl, requestOptions).then(res => res.json()); | |
} | |
function deleteOldLabels(labels) { | |
var requestOptions = { | |
method: 'delete', | |
headers: makeHeaders() | |
}; | |
return Promise.all(labels.map(label => fetch(label.url, requestOptions))); | |
} | |
function createNewLabels(labels) { | |
return Promise.all(labels.map(label => fetch(labelsUrl, { | |
method: 'post', | |
body: JSON.stringify(label), | |
headers: makeHeaders({'content-type': 'application/json'}) | |
}))); | |
} | |
getOldLabels() | |
.then(deleteOldLabels) | |
.then(() => createNewLabels(newLabels)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment