diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c3629e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/README.md b/README.md index 81910af..eb7f5f4 100644 --- a/README.md +++ b/README.md @@ -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 +``` + +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__ diff --git a/bin/label-me.js b/bin/label-me.js new file mode 100755 index 0000000..967a9d7 --- /dev/null +++ b/bin/label-me.js @@ -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 \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 + diff --git a/label-me.js b/label-me.js index ad1db3e..00a2dc2 100644 --- a/label-me.js +++ b/label-me.js @@ -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) diff --git a/labels.json b/labels.json new file mode 100644 index 0000000..d0709e8 --- /dev/null +++ b/labels.json @@ -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" } +] diff --git a/package.json b/package.json new file mode 100644 index 0000000..d7a7fdf --- /dev/null +++ b/package.json @@ -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" + } +}