├── .npmignore ├── .travis.yml ├── .gitignore ├── .editorconfig ├── package.json ├── LICENSE ├── README.md └── cli.js /.npmignore: -------------------------------------------------------------------------------- 1 | test 2 | examples 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.10" 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | .idea 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 2 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "copy-github-labels-cli", 3 | "version": "1.0.0", 4 | "description": "CLI tool to copy github labels", 5 | "keywords": [ 6 | "cli", 7 | "cli-app", 8 | "copy", 9 | "github", 10 | "labels" 11 | ], 12 | "author": { 13 | "name": "Jurgen Van de Moere", 14 | "email": "jurgen.van.de.moere@gmail.com", 15 | "url": "http://www.jvandemo.com" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "http://github.com/jvandemo/copy-github-labels-cli.git" 20 | }, 21 | "preferGlobal": true, 22 | "bin": { 23 | "copy-github-labels": "cli.js" 24 | }, 25 | "scripts": { 26 | "test": "eslint cli.js" 27 | }, 28 | "license": "MIT", 29 | "dependencies": { 30 | "chalk": "^1.1.1", 31 | "copy-github-labels": "^1.3.1", 32 | "meow": "^3.4.1" 33 | }, 34 | "devDependencies": { 35 | "eslint": "^1.6.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2015 Jurgen Van de Moere 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Copy GitHub Labels CLI 2 | 3 | CLI tool to copy GitHub labels from one repository to another. 4 | 5 | [![Build Status](https://travis-ci.org/jvandemo/copy-github-labels-cli.svg?branch=master)](https://travis-ci.org/jvandemo/copy-github-labels-cli) 6 | 7 | ![octocat](https://cloud.githubusercontent.com/assets/1859381/5422531/40186cf0-8287-11e4-941c-96cabdb3fb24.jpg) 8 | 9 | > If you only want to copy GitHub labels in a script and don't need a CLI, please use [copy-github-labels](https://github.com/jvandemo/copy-github-labels) to avoid unnecessary dependencies. 10 | 11 | ## Installation 12 | 13 | ```bash 14 | $ npm install -g copy-github-labels-cli 15 | ``` 16 | 17 | ## Usage 18 | 19 | ```bash 20 | $ copy-github-labels -t 21 | ``` 22 | 23 | ## Example 24 | 25 | To copy all labels from `angular/angular` to `jvandemo/test`: 26 | 27 | ```bash 28 | $ copy-github-labels -t e7ac7612021979b8884f6f11236c65e7723da8c1 angular/angular jvandemo/test 29 | ``` 30 | 31 | > The token above is just an example token, not a real token. You should [generate your own token](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). 32 | 33 | The output shows whether or not the copy failed for each label individually: 34 | 35 | ![copy-github-labels](https://cloud.githubusercontent.com/assets/1859381/10329347/702b3700-6cc0-11e5-9513-de309d44e314.png) 36 | 37 | ## FAQ 38 | 39 | #### Where can I get a token? 40 | 41 | Check out the GitHub guide: [Creating an access token for command-line use](https://help.github.com/articles/creating-an-access-token-for-command-line-use/). 42 | 43 | #### I'm getting an error "Unknown label: failed (Bad credentials)" 44 | 45 | This happens when your token is not valid. 46 | 47 | #### I'm getting an error "Unknown label: failed (Validation Failed)" 48 | 49 | This happens when GitHub refuses to copy the label because it is already present in the destination repository. 50 | 51 | #### I'm getting an error "Unknown label: failed (Not Found)" 52 | 53 | This happens when the destination repository cannot be found. 54 | 55 | ## License 56 | 57 | MIT 58 | 59 | ## Change log 60 | 61 | ### 1.0.0 62 | 63 | - Released production version 64 | 65 | ### 0.2.0 66 | 67 | - Added error handling 68 | - Updated documentation 69 | 70 | ### 0.1.0 71 | 72 | - Initial version 73 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | var meow = require('meow'); 4 | var chalk = require('chalk'); 5 | 6 | var source, 7 | destination, 8 | count = 0; 9 | 10 | var cli = meow({ 11 | help: [ 12 | 'Usage', 13 | ' $ copy-github-labels -t ', 14 | '', 15 | 'Options', 16 | ' -d Dry run, don\'t actually copy anything' , 17 | ' -t, --token Token to authenticate with GitHub API' , 18 | '', 19 | 'Examples', 20 | ' $ copy-github-labels -t token jvandemo/source-repo jvandemo/destination-repo', 21 | ] 22 | }, { 23 | boolean: [ 24 | 'd' 25 | ], 26 | alias: { 27 | t: 'token' 28 | } 29 | }); 30 | 31 | if (!cli.flags.token) { 32 | cli.showHelp(1); 33 | } 34 | 35 | if (cli.input.length < 2) { 36 | cli.showHelp(1); 37 | } 38 | 39 | source = cli.input[0]; 40 | destination = cli.input[1]; 41 | 42 | var options = { 43 | dryRun: cli.flags.d 44 | }; 45 | var copyGitHubLabels = require('copy-github-labels')(options); 46 | 47 | copyGitHubLabels.authenticate({ 48 | type: "token", 49 | token: cli.flags.token 50 | }); 51 | 52 | if(cli.flags.d){ 53 | console.log(chalk.yellow('Dry run, no labels are copied for real:')); 54 | } 55 | 56 | 57 | /** 58 | * Copy labels. 59 | * 60 | * The returned label looks like this: 61 | * { 62 | * "url":"https://api.github.com/repos/jvandemo/testje/labels/effort2:%20medium%20(day)", 63 | * "name":"effort2: medium (day)", 64 | * "color":"bfe5bf", 65 | * "meta":{ 66 | * "x-ratelimit-limit":"5000", 67 | * "x-ratelimit-remaining":"4832", 68 | * "x-ratelimit-reset":"1444192372", 69 | * "x-oauth-scopes":"gist, repo, user", 70 | * "location":"https://api.github.com/repos/jvandemo/testje/labels/effort2:%20medium%20(day)", 71 | * "etag":"\"87c21039795ca6752192f8cfe5954ecb\"", 72 | * "status":"201 Created" 73 | * } 74 | * } 75 | */ 76 | 77 | copyGitHubLabels.copy(source, destination, function (err, label){ 78 | 79 | var error = JSON.parse(err); 80 | var labelName = 'Unknown label'; 81 | 82 | if(label && label.name){ 83 | labelName = label.name; 84 | } 85 | 86 | count++; 87 | 88 | if(err){ 89 | 90 | // If error occurs during first iteration and no label is returned, 91 | // it is probably a general error like an invalid token so we should exit 92 | // while we still can. 93 | // if((!label) && (count === 1)){ 94 | // console.error(error.message); 95 | // process.exit(1); 96 | // } 97 | return console.log(chalk.dim(count + '. ') + chalk.bold(labelName) + ': ' + chalk.red('failed (' + error.message) + ')'); 98 | } 99 | 100 | console.log(chalk.dim(count + '. ') + chalk.bold(labelName) + ': ' + chalk.green('ok')); 101 | }); 102 | --------------------------------------------------------------------------------