Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a command for adding the labels to a github repository #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ If you're looking for some definitions, and maybe some examples, then hopefully

## How to use

You don't want to be entering all of these labels manually of course! Hopefully you have node installed, and can install [git-label](https://github.com/jasonbellamy/git-label). I had no luck running the CLI version of git-label, so I created a handy script to add the labels to your Github project. The script uses the Github API, so you'll need a [Personal Access Token](https://github.com/settings/tokens) with the permission to access the repo you want to add labels for.

Checkout this repo, or just copy the script to a file of your choosing. Add your token and set the repo URI, then run the script via command line `node label-me.js`. I didn't see any point in trying to fix the CLI interface, nor making this script into a node package, as node isn't really my thing.

This package includes a command `label-me` that can be installed globally to add the labels to a given project using the Github API.
```
label-me <user/repo> <api_token>
```

Install this package globally and then run `label-me`
```
npm install -g label-me
label-me me/my_repo `cat supersecret`
```

API tokens can be created at https://github.com/settings/tokens

## Definitions
__Assignment to Issues or Pull Requests__
Expand Down
37 changes: 37 additions & 0 deletions bin/label-me.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node
var process = require('process');
var gitLabel = require('git-label');
var labels = require('../labels.json');

var usage = 'Usage: label-me <user/repo> <api-token>\n\n'
+ 'API tokens can be created from https://github.com/settings/tokens';

if (process.argv.length !== 4) {
console.error(usage);
process.exit(1);
}

if (!process.argv[2].match(/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+/)) {
console.error('Given user/repo is not valid');
console.error(usage);
process.exit(2);
}

if (process.argv[3].length !== 40) {
console.error('Given token does not seem to be valid');
console.error(usage);
process.exit(3);
}

var config = {
api : 'https://api.github.com',
repo : process.argv[2],
token : process.argv[3]
};


// add specified labels from a repo
gitLabel.add(config, labels)
.then(console.log) //=> success message
.catch(console.log) //=> error message

22 changes: 1 addition & 21 deletions label-me.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,7 @@ var config = {
token : 'xxx'
};

var labels = [
{ "name": "Priority: Low", "color": "#009800" },
{ "name": "Priority: Medium", "color": "#fbca04" },
{ "name": "Priority: High", "color": "#eb6420" },
{ "name": "Priority: Critical", "color": "#e11d21" },
{ "name": "Status: Abandoned", "color": "#000000" },
{ "name": "Status: Accepted", "color": "#009800" },
{ "name": "Status: Available", "color": "#bfe5bf" },
{ "name": "Status: Blocked", "color": "#e11d21" },
{ "name": "Status: Completed", "color": "#006b75" },
{ "name": "Status: In Progress", "color": "#cccccc" },
{ "name": "Status: On Hold", "color": "#e11d21" },
{ "name": "Status: Review Needed", "color": "#fbca04" },
{ "name": "Status: Revision Needed", "color": "#e11d21" },
{ "name": "Type: Bug", "color": "#e11d21" },
{ "name": "Type: Maintenance", "color": "#fbca04" },
{ "name": "Type: Enhancement", "color": "#84b6eb" },
{ "name": "Type: Question", "color": "#cc317c" },
{ "name": "¯\\_[ツ]_/¯", "color": "#FFC107" },
{ "name": "[ノಠ益ಠ]ノ彡┻━┻", "color": "#333333" }
];
var labels = require('./labels.json');

// add specified labels from a repo
gitLabel.add(config, labels)
Expand Down
21 changes: 21 additions & 0 deletions labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{ "name": "Priority: Low", "color": "#009800" },
{ "name": "Priority: Medium", "color": "#fbca04" },
{ "name": "Priority: High", "color": "#eb6420" },
{ "name": "Priority: Critical", "color": "#e11d21" },
{ "name": "Status: Abandoned", "color": "#000000" },
{ "name": "Status: Accepted", "color": "#009800" },
{ "name": "Status: Available", "color": "#bfe5bf" },
{ "name": "Status: Blocked", "color": "#e11d21" },
{ "name": "Status: Completed", "color": "#006b75" },
{ "name": "Status: In Progress", "color": "#cccccc" },
{ "name": "Status: On Hold", "color": "#e11d21" },
{ "name": "Status: Review Needed", "color": "#fbca04" },
{ "name": "Status: Revision Needed", "color": "#e11d21" },
{ "name": "Type: Bug", "color": "#e11d21" },
{ "name": "Type: Maintenance", "color": "#fbca04" },
{ "name": "Type: Enhancement", "color": "#84b6eb" },
{ "name": "Type: Question", "color": "#cc317c" },
{ "name": "¯\\_[ツ]_/¯", "color": "#FFC107" },
{ "name": "[ノಠ益ಠ]ノ彡┻━┻", "color": "#333333" }
]
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "sensible-github-labels",
"version": "1.0.0",
"description": "Github labels for teams that like workflows and structure",
"main": "label-me.js",
"bin": {
"label-me": "bin/label-me.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Relequestual/sensible-github-labels.git"
},
"keywords": [
"labels",
"github"
],
"author": "Ben Hutton (https://github.com/Relequestual)",
"license": "MIT",
"bugs": {
"url": "https://github.com/Relequestual/sensible-github-labels/issues"
},
"homepage": "https://github.com/Relequestual/sensible-github-labels#readme",
"dependencies": {
"git-label": "^4.1.1"
}
}