├── .babelrc ├── .gitignore ├── .travis.yml ├── contributing.md ├── dist ├── index.js ├── lib │ ├── prompt.js │ └── repo.js └── util │ └── run.js ├── license ├── package.json ├── readme.md └── src ├── index.js ├── lib ├── prompt.js └── repo.js └── util └── run.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ "es2015" ] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 'stable' 4 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. 3 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | 4 | var _commander = require('commander'); 5 | 6 | var _commander2 = _interopRequireDefault(_commander); 7 | 8 | var _run = require('./util/run'); 9 | 10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 11 | 12 | _commander2.default.option('-i, --interactive', 'run in interactive mode').option('-a, --api ', 'api url').option('-t, --token ', 'api token').option('-r, --repo ', 'repo name [username/repo]').option('-p, --pattern ', 'globbing pattern to the label packages'); 13 | 14 | _commander2.default.command('add').description('Add the specified labels to a repo').action(function () { 15 | return (0, _run.run)('add', _commander2.default.interactive, _commander2.default).then(console.log).catch(console.log); 16 | }); 17 | 18 | _commander2.default.command('remove').description('Remove the specified labels from a repo').action(function () { 19 | return (0, _run.run)('remove', _commander2.default.interactive, _commander2.default).then(console.log).catch(console.log); 20 | }); 21 | 22 | _commander2.default.parse(process.argv); -------------------------------------------------------------------------------- /dist/lib/prompt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.prompt = prompt; 7 | 8 | var _inquirer = require('inquirer'); 9 | 10 | var _inquirer2 = _interopRequireDefault(_inquirer); 11 | 12 | var _repo = require('./repo'); 13 | 14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 15 | 16 | /** 17 | * Prompt the user to provide information for git-label 18 | * 19 | * @name prompt 20 | * @function 21 | * @return {Promise} success or error message 22 | */ 23 | function prompt() { 24 | var questions = [{ type: "input", name: "api", message: "api url", default: "https://api.github.com" }, { type: "input", name: "repo", message: "repo name [username/repo]", default: function _default() { 25 | var done = this.async(); 26 | return (0, _repo.getRepo)('.git/config').then(done).catch(done); 27 | } 28 | }, { type: "input", name: "token", message: "api token" }, { type: "input", name: "pattern", message: "globbing pattern to the label packages" }]; 29 | 30 | return new Promise(function (resolve, reject) { 31 | _inquirer2.default.prompt(questions, function (_ref) { 32 | var api = _ref.api; 33 | var repo = _ref.repo; 34 | var token = _ref.token; 35 | var pattern = _ref.pattern; 36 | 37 | resolve({ server: { api: api, repo: repo, token: token }, pattern: pattern }); 38 | }); 39 | }); 40 | } -------------------------------------------------------------------------------- /dist/lib/repo.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.getRepo = getRepo; 7 | 8 | var _fs = require('fs'); 9 | 10 | /** 11 | * Extracts the git repo (name/repo) from the provided path. 12 | * 13 | * @name getRepo 14 | * @function 15 | * @param {string} path the path to extract the git information from 16 | * @return {Promise} the extracted repo (name/repo) 17 | */ 18 | function getRepo(path) { 19 | return new Promise(function (resolve, reject) { 20 | (0, _fs.readFile)(path, function (err, res) { 21 | if (err) { 22 | reject(null); 23 | } 24 | 25 | resolve(/(:)(.+)(\.git)/g.exec(res)[2].split('/').filter(function (key, index, xs) { 26 | return index > xs.length - 3; 27 | }).join('/')); 28 | }); 29 | }); 30 | } -------------------------------------------------------------------------------- /dist/util/run.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.run = run; 7 | 8 | var _gitLabel = require('git-label'); 9 | 10 | var _prompt = require('../lib/prompt'); 11 | 12 | /** 13 | * Utility function to determine which type of cli to use 14 | * 15 | * @name run 16 | * @function 17 | * @param {Function} type add/remove function 18 | * @param {Boolean} interactive should the interactive prompt be used 19 | * @param {Object} options the configuration object 20 | * @param {String} options.server.api the api endpoint to connect to 21 | * @param {String} options.server.token the api token to use 22 | * @param {String} options.server.repo the git repo to manipulate 23 | * @param {Array} options.pattern globbing pattern to the label packages 24 | */ 25 | function run(type, interactive, _ref) { 26 | var api = _ref.api; 27 | var token = _ref.token; 28 | var repo = _ref.repo; 29 | var pattern = _ref.pattern; 30 | 31 | var fn = type === 'add' ? _gitLabel.add : _gitLabel.remove; 32 | if (interactive) { 33 | return (0, _prompt.prompt)().then(function (_ref2) { 34 | var server = _ref2.server; 35 | var pattern = _ref2.pattern; 36 | return (0, _gitLabel.find)(pattern).then(fn.bind(null, server)); 37 | }); 38 | } 39 | 40 | return (0, _gitLabel.find)(pattern).then(fn.bind(null, { api: api, token: token, repo: repo })); 41 | } -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jason Bellamy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "git-label-cli", 3 | "description": "CLI utility for git-label", 4 | "version": "3.0.0", 5 | "homepage": "https://github.com/jasonbellamy", 6 | "author": { 7 | "name": "Jason Bellamy", 8 | "email": "j@sonbellamy.com", 9 | "url": "http://jasonbellamy.com" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/jasonbellamy/git-label-cli.git" 14 | }, 15 | "bugs": { 16 | "url": "https://github.com/jasonbellamy/git-label-cli/issues" 17 | }, 18 | "license": "MIT", 19 | "bin": { 20 | "git-label": "dist/index.js" 21 | }, 22 | "engines": { 23 | "node": ">= 4.0.0" 24 | }, 25 | "scripts": { 26 | "build": "babel -d dist src", 27 | "clean": "rm -rf dist && mkdir dist", 28 | "watch": "babel -w -d dist src", 29 | "preversion": "npm run clean && npm run build", 30 | "postpublish": "git push && git push --tag" 31 | }, 32 | "dependencies": { 33 | "commander": "^2.9.0", 34 | "git-label": "^4.1.0", 35 | "glob": "^6.0.3", 36 | "inquirer": "^0.11.1" 37 | }, 38 | "devDependencies": { 39 | "babel": "^6.1.18", 40 | "babel-cli": "^6.3.17", 41 | "babel-preset-es2015": "^6.1.18", 42 | "babel-register": "^6.2.0" 43 | }, 44 | "keywords": [ 45 | "cli", 46 | "labels", 47 | "github", 48 | "git", 49 | "utils" 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # git-label-cli 2 | 3 | > CLI utility for [git-label](https://github.com/jasonbellamy/git-label) 4 | 5 | 6 | ## Getting Started 7 | 8 | - Install with [NPM](https://www.npmjs.org/) - `npm install --global git-label-cli` 9 | 10 | 11 | ## Usage 12 | 13 | ```bash 14 | $ git-label --help 15 | 16 | Usage: git-label [options] [command] 17 | 18 | 19 | Commands: 20 | 21 | add Add the specified labels to a repo 22 | remove Remove the specified labels from a repo 23 | 24 | Options: 25 | 26 | -h, --help output usage information 27 | -i, --interactive run in interactive mode 28 | -a, --api api url 29 | -t, --token api token 30 | -r, --repo repo name [username/repo] 31 | -p, --pattern globbing pattern to the label packages 32 | ``` 33 | 34 | 35 | ## Developing 36 | 37 | [git-label-cli](https://github.com/jasonbellamy/git-label-cli) is built using **ES6**. Run the following task to compile the `src/` into `dist/`. 38 | 39 | ```bash 40 | npm run build 41 | ``` 42 | 43 | 44 | ## Related 45 | 46 | - [git-label](https://github.com/jasonbellamy/git-label) - API for this module 47 | - [git-label-packages](https://github.com/jasonbellamy/git-label-packages) - Default label packages for this module 48 | 49 | 50 | ## Contributing 51 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. 52 | 53 | 54 | ## License 55 | Copyright (c) 2016 [Jason Bellamy ](http://jasonbellamy.com) 56 | Licensed under the MIT license. 57 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import program from 'commander'; 4 | import {run} from './util/run'; 5 | 6 | 7 | program 8 | .option('-i, --interactive', 'run in interactive mode') 9 | .option('-a, --api ', 'api url') 10 | .option('-t, --token ', 'api token') 11 | .option('-r, --repo ', 'repo name [username/repo]') 12 | .option('-p, --pattern ', 'globbing pattern to the label packages'); 13 | 14 | program 15 | .command('add') 16 | .description('Add the specified labels to a repo') 17 | .action(() => run('add', program.interactive, program).then(console.log).catch(console.log)); 18 | 19 | program 20 | .command('remove') 21 | .description('Remove the specified labels from a repo') 22 | .action(() => run('remove', program.interactive, program).then(console.log).catch(console.log)); 23 | 24 | program.parse(process.argv); 25 | -------------------------------------------------------------------------------- /src/lib/prompt.js: -------------------------------------------------------------------------------- 1 | import inquirer from 'inquirer'; 2 | import {getRepo} from './repo'; 3 | 4 | 5 | /** 6 | * Prompt the user to provide information for git-label 7 | * 8 | * @name prompt 9 | * @function 10 | * @return {Promise} success or error message 11 | */ 12 | export function prompt() { 13 | const questions = [ 14 | {type: "input", name: "api", message: "api url", default: "https://api.github.com"}, 15 | {type: "input", name: "repo", message: "repo name [username/repo]", default() { 16 | const done = this.async(); 17 | return getRepo('.git/config').then(done).catch(done); 18 | }}, 19 | {type: "input", name: "token", message: "api token"}, 20 | {type: "input", name: "pattern", message: "globbing pattern to the label packages"} 21 | ]; 22 | 23 | return new Promise((resolve, reject) => { 24 | inquirer.prompt(questions, ({api, repo, token, pattern}) => { 25 | resolve({server: {api, repo, token}, pattern}); 26 | }); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /src/lib/repo.js: -------------------------------------------------------------------------------- 1 | import {readFile} from 'fs'; 2 | 3 | 4 | /** 5 | * Extracts the git repo (name/repo) from the provided path. 6 | * 7 | * @name getRepo 8 | * @function 9 | * @param {string} path the path to extract the git information from 10 | * @return {Promise} the extracted repo (name/repo) 11 | */ 12 | export function getRepo(path) { 13 | return new Promise((resolve, reject) => { 14 | readFile(path, function(err, res) { 15 | if (err) { reject(null); } 16 | 17 | resolve((/(:)(.+)(\.git)/g).exec(res)[2] 18 | .split('/') 19 | .filter((key, index, xs) => index > xs.length - 3) 20 | .join('/')); 21 | }); 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /src/util/run.js: -------------------------------------------------------------------------------- 1 | import {add, remove, find} from 'git-label'; 2 | import {prompt} from '../lib/prompt'; 3 | 4 | 5 | /** 6 | * Utility function to determine which type of cli to use 7 | * 8 | * @name run 9 | * @function 10 | * @param {Function} type add/remove function 11 | * @param {Boolean} interactive should the interactive prompt be used 12 | * @param {Object} options the configuration object 13 | * @param {String} options.server.api the api endpoint to connect to 14 | * @param {String} options.server.token the api token to use 15 | * @param {String} options.server.repo the git repo to manipulate 16 | * @param {Array} options.pattern globbing pattern to the label packages 17 | */ 18 | export function run(type, interactive, {api, token, repo, pattern}) { 19 | const fn = type === 'add' ? add : remove; 20 | if (interactive) { 21 | return prompt().then(({server, pattern}) => find(pattern).then(fn.bind(null, server))); 22 | } 23 | 24 | return find(pattern).then(fn.bind(null, {api, token, repo})); 25 | } 26 | --------------------------------------------------------------------------------