Skip to content

Instantly share code, notes, and snippets.

@pineapplemachine
Created March 1, 2018 14:10
Show Gist options
  • Select an option

  • Save pineapplemachine/e8bb5440188201298a86f39e20671f78 to your computer and use it in GitHub Desktop.

Select an option

Save pineapplemachine/e8bb5440188201298a86f39e20671f78 to your computer and use it in GitHub Desktop.
Add standard labels to a github repository
const axios = require("axios");
// The labels that will be added
const labels = [
{
"name": "effort: high",
"color": "7319e7",
"description": "The issue will probably take a single contributor several days of work to resolve."
},
{
"name": "effort: low",
"color": "bfd4ff",
"description": "The issue will probably take a single contributor no more than one day of work to resolve."
},
{
"name": "effort: moderate",
"color": "58b0ff",
"description": "The issue will probably take a single contributor one or two days of work to resolve."
},
{
"name": "effort: very high",
"color": "430997",
"description": "The issue will probably take a single contributor more than a week of work to resolve."
},
{
"name": "issue: duplicate",
"color": "cccccc",
"description": "The issue was closed because it's a duplicate of another issue."
},
{
"name": "issue: invalid",
"color": "e6e6e6",
"description": "The issue was closed because it's inapplicable or doesn't make sense."
},
{
"name": "issue: question",
"color": "b5ffef",
"description": "The issue is a question, and it should be closed after the question is answered."
},
{
"name": "issue: wontfix",
"color": "fafafa",
"description": "The issue was closed because the relevant changes are not justifiable."
},
{
"name": "meta: blocked",
"color": "88f2b0",
"description": "The issue cannot be resolved right now, but should be in the future."
},
{
"name": "meta: good first issue",
"color": "50e5ff",
"description": "The issue is especially suitable for first-time contributors."
},
{
"name": "meta: needs work",
"color": "ffd0f4",
"description": "The issue cannot progress until additional work is done."
},
{
"name": "meta: next release",
"color": "b60205",
"description": "The issue must be resolved before the next package version can be released."
},
{
"name": "priority: critical",
"color": "ff47c0",
"description": "The issue must be resolved as soon as possible."
},
{
"name": "priority: high",
"color": "fb1055",
"description": "The issue substantially impedes people's ability to use the software."
},
{
"name": "priority: low",
"color": "efe8e0",
"description": "The issue has only a small impact on people using the software."
},
{
"name": "priority: medium",
"color": "ffaa79",
"description": "The issue makes it more difficult for people to use the software."
},
{
"name": "priority: trivial",
"color": "fff7ee",
"description": "The issue has very little impact on people using the software."
},
{
"name": "type: bug",
"color": "ee0701",
"description": "The issue involves incorrect or unexpected behavior."
},
{
"name": "type: code quality",
"color": "12e0c4",
"description": "The issue involves code organization and readability."
},
{
"name": "type: documentation",
"color": "1d76db",
"description": "This issue pertains to the clarity or exhaustiveness of package documentation."
},
{
"name": "type: feature",
"color": "fab704",
"description": "The issue involves adding new or extended behavior to the package."
},
{
"name": "type: integration",
"color": "007b75",
"description": "The issue involves interactions with other software."
},
{
"name": "type: optimization",
"color": "f9e870",
"description": "The issue involves making existing functionality more performant."
},
{
"name": "type: polish",
"color": "fd8042",
"description": "The issue involves making existing functionality more usable."
},
{
"name": "type: security",
"color": "16aa26",
"description": "The issue pertains to security threats and vulnerabilities."
},
{
"name": "type: stability",
"color": "bf45f9",
"description": "The issue pertains to automated testing or other tools for verifying code correctness."
}
];
// Github API helper
class Github{
constructor(options){
this.owner = options.owner;
this.repository = options.repository;
this.apiAccessToken = options.apiAccessToken;
}
getApiUrl(endpoint){
const host = `https://api.github.com`;
const url = `${host}/repos/${this.owner}/${this.repository}/${endpoint}`;
return `${url}?access_token=${this.apiAccessToken}`;
}
async getLabels(){
return (await axios({
method: "get",
url: this.getApiUrl("labels"),
headers: {
"Accept": "application/vnd.github.symmetra-preview+json",
},
})).data;
}
async deleteLabel(labelName){
return await axios({
method: "delete",
url: this.getApiUrl(`labels/${labelName}`),
headers: {
"Accept": "application/vnd.github.symmetra-preview+json",
},
});
}
async deleteLabels(labelNames){
return await Promise.all(labelNames.map(name => this.deleteLabel(name)));
}
async deleteAllLabels(){
return await this.deleteLabels(
(await this.getLabels()).map(label => label.name)
);
}
async addLabel(label){
return await axios({
method: "post",
url: this.getApiUrl("labels"),
headers: {
"Accept": "application/vnd.github.symmetra-preview+json",
},
data: label,
});
}
async addLabels(labels){
return await Promise.all(labels.map(label => this.addLabel(label)));
}
}
(async () => {
const target = new Github({
owner: "mapita", // Owner of the repo to add labels to
repository: "shorter", // Name of the repo to add labels to
apiAccessToken: "[YOUR PERSONAL ACCESS TOKEN]",
});
try{
await target.addLabels(labels);
}catch(error){
console.error("Encountered an error.");
console.error(error);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment