├── .editorconfig ├── .eslintrc.json ├── .gitattributes ├── .gitignore ├── .verb.md ├── LICENSE ├── README.md ├── cli.js ├── index.js └── package.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | indent_size = 2 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [{**/{actual,fixtures,expected,templates}/**,*.md}] 12 | trim_trailing_whitespace = false 13 | insert_final_newline = false -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "ecmaFeatures": { 3 | "modules": true, 4 | "experimentalObjectRestSpread": true 5 | }, 6 | 7 | "env": { 8 | "browser": false, 9 | "es6": true, 10 | "node": true, 11 | "mocha": true 12 | }, 13 | 14 | "globals": { 15 | "document": false, 16 | "navigator": false, 17 | "window": false 18 | }, 19 | 20 | "rules": { 21 | "accessor-pairs": 2, 22 | "arrow-spacing": [2, { "before": true, "after": true }], 23 | "block-spacing": [2, "always"], 24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }], 25 | "comma-dangle": [2, "never"], 26 | "comma-spacing": [2, { "before": false, "after": true }], 27 | "comma-style": [2, "last"], 28 | "constructor-super": 2, 29 | "curly": [2, "multi-line"], 30 | "dot-location": [2, "property"], 31 | "eol-last": 2, 32 | "eqeqeq": [2, "allow-null"], 33 | "generator-star-spacing": [2, { "before": true, "after": true }], 34 | "handle-callback-err": [2, "^(err|error)$" ], 35 | "indent": [2, 2, { "SwitchCase": 1 }], 36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }], 37 | "keyword-spacing": [2, { "before": true, "after": true }], 38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }], 39 | "new-parens": 2, 40 | "no-array-constructor": 2, 41 | "no-caller": 2, 42 | "no-class-assign": 2, 43 | "no-cond-assign": 2, 44 | "no-const-assign": 2, 45 | "no-control-regex": 2, 46 | "no-debugger": 2, 47 | "no-delete-var": 2, 48 | "no-dupe-args": 2, 49 | "no-dupe-class-members": 2, 50 | "no-dupe-keys": 2, 51 | "no-duplicate-case": 2, 52 | "no-empty-character-class": 2, 53 | "no-eval": 2, 54 | "no-ex-assign": 2, 55 | "no-extend-native": 2, 56 | "no-extra-bind": 2, 57 | "no-extra-boolean-cast": 2, 58 | "no-extra-parens": [2, "functions"], 59 | "no-fallthrough": 2, 60 | "no-floating-decimal": 2, 61 | "no-func-assign": 2, 62 | "no-implied-eval": 2, 63 | "no-inner-declarations": [2, "functions"], 64 | "no-invalid-regexp": 2, 65 | "no-irregular-whitespace": 2, 66 | "no-iterator": 2, 67 | "no-label-var": 2, 68 | "no-labels": 2, 69 | "no-lone-blocks": 2, 70 | "no-mixed-spaces-and-tabs": 2, 71 | "no-multi-spaces": 2, 72 | "no-multi-str": 2, 73 | "no-multiple-empty-lines": [2, { "max": 1 }], 74 | "no-native-reassign": 0, 75 | "no-negated-in-lhs": 2, 76 | "no-new": 2, 77 | "no-new-func": 2, 78 | "no-new-object": 2, 79 | "no-new-require": 2, 80 | "no-new-wrappers": 2, 81 | "no-obj-calls": 2, 82 | "no-octal": 2, 83 | "no-octal-escape": 2, 84 | "no-proto": 0, 85 | "no-redeclare": 2, 86 | "no-regex-spaces": 2, 87 | "no-return-assign": 2, 88 | "no-self-compare": 2, 89 | "no-sequences": 2, 90 | "no-shadow-restricted-names": 2, 91 | "no-spaced-func": 2, 92 | "no-sparse-arrays": 2, 93 | "no-this-before-super": 2, 94 | "no-throw-literal": 2, 95 | "no-trailing-spaces": 0, 96 | "no-undef": 2, 97 | "no-undef-init": 2, 98 | "no-unexpected-multiline": 2, 99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }], 100 | "no-unreachable": 2, 101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }], 102 | "no-useless-call": 0, 103 | "no-with": 2, 104 | "one-var": [0, { "initialized": "never" }], 105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }], 106 | "padded-blocks": [0, "never"], 107 | "quotes": [2, "single", "avoid-escape"], 108 | "radix": 2, 109 | "semi": [2, "always"], 110 | "semi-spacing": [2, { "before": false, "after": true }], 111 | "space-before-blocks": [2, "always"], 112 | "space-before-function-paren": [2, "never"], 113 | "space-in-parens": [2, "never"], 114 | "space-infix-ops": 2, 115 | "space-unary-ops": [2, { "words": true, "nonwords": false }], 116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }], 117 | "use-isnan": 2, 118 | "valid-typeof": 2, 119 | "wrap-iife": [2, "any"], 120 | "yoda": [2, "never"] 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # always ignore files 2 | *.DS_Store 3 | *.sublime-* 4 | 5 | # test related, or directories generated by tests 6 | test/actual 7 | actual 8 | coverage 9 | .nyc* 10 | 11 | # npm 12 | node_modules 13 | npm-debug.log 14 | 15 | # yarn 16 | yarn.lock 17 | yarn-error.log 18 | 19 | # misc 20 | _gh_pages 21 | _draft 22 | _drafts 23 | bower_components 24 | vendor 25 | temp 26 | tmp 27 | TODO.md 28 | package-lock.json -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | 2 | Wrapper around [travis-ci][] to simplify enabling Travis CI for a project. 3 | 4 | ### HEADS UP! 5 | 6 | Travis can only enable a project it knows about. If necessary, use [sync-travis][] to sync your latest GitHub projects first. 7 | 8 | ## Usage 9 | 10 | ### CLI 11 | 12 | From the command line: 13 | 14 | ```bash 15 | $ enable-travis 16 | ``` 17 | 18 | Next, you will be prompted to enter your github username and auth token, and the `owner/repo` to enable. Answers are saved for the next run (except for repo). 19 | 20 | ```bash 21 | Please provide the repo to enable, your github username and auth token: 22 | 23 | ? owner/repo: jonschlinkert/micromatch 24 | ? username: jonschlinkert 25 | ? GitHub auth token: ******** 26 | ``` 27 | 28 | Done! It will attempt to fill in default answers using the git-remote-origin URL, the git username, and package.json project name. But you can override these as necessary. 29 | 30 | Let me know if you have any issues or feature requests! 31 | 32 | ### API 33 | 34 | {%= include("install-npm", {save: true}) %} 35 | 36 | ```js 37 | var enable = require('{%= name %}'); 38 | 39 | var options = {repo: 'foo/bar', username: 'foo', GITHUB_OAUTH_TOKEN: 'XXXXXX'}; 40 | enable(options, function (err, res) { 41 | console.log(res); 42 | //=> { result: true } 43 | }); 44 | ``` 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2017, Jon Schlinkert. 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # enable-travis [![NPM version](https://img.shields.io/npm/v/enable-travis.svg?style=flat)](https://www.npmjs.com/package/enable-travis) [![NPM monthly downloads](https://img.shields.io/npm/dm/enable-travis.svg?style=flat)](https://npmjs.org/package/enable-travis) [![NPM total downloads](https://img.shields.io/npm/dt/enable-travis.svg?style=flat)](https://npmjs.org/package/enable-travis) 2 | 3 | > CLI to enable Travis CI for a node.js project. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | ```sh 10 | $ npm install --save enable-travis 11 | ``` 12 | 13 | Install with [yarn](https://yarnpkg.com): 14 | 15 | ```sh 16 | $ yarn add enable-travis 17 | ``` 18 | 19 | Wrapper around [travis-ci](https://github.com/pwmckenna/node-travis-ci) to simplify enabling Travis CI for a project. 20 | 21 | ### HEADS UP! 22 | 23 | Travis can only enable a project it knows about. If necessary, use [sync-travis](https://github.com/jonschlinkert/sync-travis) to sync your latest GitHub projects first. 24 | 25 | ## Usage 26 | 27 | ### CLI 28 | 29 | From the command line: 30 | 31 | ```bash 32 | $ enable-travis 33 | ``` 34 | 35 | Next, you will be prompted to enter your github username and auth token, and the `owner/repo` to enable. Answers are saved for the next run (except for repo). 36 | 37 | ```bash 38 | Please provide the repo to enable, your github username and auth token: 39 | 40 | ? owner/repo: jonschlinkert/micromatch 41 | ? username: jonschlinkert 42 | ? GitHub auth token: ******** 43 | ``` 44 | 45 | Done! It will attempt to fill in default answers using the git-remote-origin URL, the git username, and package.json project name. But you can override these as necessary. 46 | 47 | Let me know if you have any issues or feature requests! 48 | 49 | ### API 50 | 51 | Install with [npm](https://www.npmjs.com/): 52 | 53 | ```sh 54 | $ npm install --save enable-travis 55 | ``` 56 | 57 | ```js 58 | var enable = require('enable-travis'); 59 | 60 | var options = {repo: 'foo/bar', username: 'foo', GITHUB_OAUTH_TOKEN: 'XXXXXX'}; 61 | enable(options, function (err, res) { 62 | console.log(res); 63 | //=> { result: true } 64 | }); 65 | ``` 66 | 67 | ## About 68 | 69 | ### Related projects 70 | 71 | [sync-travis](https://www.npmjs.com/package/sync-travis): Sync your Github projects with Travis CI, to ensure it's updated with your latest projects… [more](https://github.com/jonschlinkert/sync-travis) | [homepage](https://github.com/jonschlinkert/sync-travis "Sync your Github projects with Travis CI, to ensure it's updated with your latest projects before executing other commands.") 72 | 73 | ### Contributing 74 | 75 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new). 76 | 77 | ### Building docs 78 | 79 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_ 80 | 81 | To generate the readme, run the following command: 82 | 83 | ```sh 84 | $ npm install -g verbose/verb#dev verb-generate-readme && verb 85 | ``` 86 | 87 | ### Running tests 88 | 89 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command: 90 | 91 | ```sh 92 | $ npm install && npm test 93 | ``` 94 | 95 | ### Author 96 | 97 | **Jon Schlinkert** 98 | 99 | * [github/jonschlinkert](https://github.com/jonschlinkert) 100 | * [twitter/jonschlinkert](https://twitter.com/jonschlinkert) 101 | 102 | ### License 103 | 104 | Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert). 105 | Released under the [MIT License](LICENSE). 106 | 107 | *** 108 | 109 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on July 23, 2017._ -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | process.title = 'enable-travis'; 4 | 5 | var argv = require('minimist')(process.argv.slice(2)); 6 | var log = require('log-utils'); 7 | var Enquirer = require('enquirer'); 8 | var DataStore = require('data-store'); 9 | 10 | var store = new DataStore('enable-travis'); 11 | var enquirer = new Enquirer(); 12 | enquirer.register('password', require('prompt-password')); 13 | 14 | if (argv.set) { 15 | var args = argv.set.split(/[=:,]/); 16 | console.log(args) 17 | store.set.apply(store, args); 18 | process.exit(1); 19 | } 20 | 21 | if (argv.get) { 22 | console.log(store.get(argv.get)); 23 | process.exit(1); 24 | } 25 | 26 | var repo = require('git-repo-name'); 27 | var user = require('git-user-name'); 28 | var name = require('git-username'); 29 | var pkg = require('load-pkg'); 30 | 31 | var username = name() || user() || store.get('username'); 32 | var token = store.get('GITHUB_OAUTH_TOKEN'); 33 | var repository = repo.sync() || pkg && pkg.name; 34 | var enable = require('./'); 35 | 36 | run(function (options) { 37 | enable(options, function (err, res) { 38 | if (err) { 39 | console.log(err); 40 | console.log(log.yellow('Oops! Travis doesn\'t seem know about this project yet.')); 41 | console.log(log.yellow('Use "https://github.com/jonschlinkert/sync-travis" to ')); 42 | console.log(log.yellow('update Travis CI with your latest GitHub projects.')); 43 | process.exit(0); 44 | } 45 | if (res && res.result) { 46 | console.log(log.symbol.success + ' ' + log.green(options.repo), 'has been enabled!'); 47 | } 48 | }); 49 | }); 50 | 51 | function run(cb) { 52 | console.log('Please provide the repo to enable, your github username and auth token:'); 53 | console.log(); 54 | 55 | var prompts = []; 56 | 57 | prompts.push({ 58 | type: 'input', 59 | name: 'repo', 60 | message: log.bold('owner/repo'), 61 | default: username + '/' + repository 62 | }); 63 | 64 | prompts.push({ 65 | type: 'input', 66 | name: 'username', 67 | message: log.bold('username'), 68 | default: username 69 | }); 70 | 71 | prompts.push({ 72 | type: 'password', 73 | name: 'GITHUB_OAUTH_TOKEN', 74 | message: log.bold('GitHub auth token'), 75 | default: token 76 | }); 77 | 78 | enquirer.ask(prompts) 79 | .then(function(answers) { 80 | for (var key in answers) { 81 | if (key !== repo) { 82 | store.set(key, answers[key]); 83 | } 84 | } 85 | 86 | if (answers) { 87 | if (answers.repo && answers.repo.indexOf('/') === -1) { 88 | console.log(log.red('github repo must be in the form of `owner/repo')); 89 | process.exit(1); 90 | } 91 | cb(answers); 92 | } else { 93 | console.log(log.green('\n Got it. All is good.')); 94 | process.exit(0); 95 | } 96 | }) 97 | .catch(function(err) { 98 | console.error(err); 99 | process.exit(1); 100 | }); 101 | } 102 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * enable-travis 3 | * 4 | * Copyright (c) 2015-2017, Jon Schlinkert. 5 | * Released under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var Travis = require('travis-ci'); 11 | 12 | /** 13 | * Expose `enable` 14 | */ 15 | 16 | module.exports = enable; 17 | 18 | /** 19 | * Enable a travis project 20 | */ 21 | 22 | function enable(options, cb) { 23 | options = options || {}; 24 | var travis = new Travis({ 25 | version: '2.0.0', 26 | // user-agent needs to start with "Travis" 27 | // https://github.com/travis-ci/travis-ci/issues/5649 28 | headers: {'user-agent': 'Travis: jonschlinkert/enable-travis'} 29 | }); 30 | 31 | travis.auth.github.post({ 32 | github_token: options.GITHUB_OAUTH_TOKEN 33 | }, function(err, res) { 34 | if (err) return cb(err); 35 | 36 | travis.authenticate({ 37 | access_token: res.access_token 38 | }, function(err) { 39 | 40 | if (err) return cb(err); 41 | var segs = options.repo.split('/'); 42 | 43 | travis.repos(segs[0], segs[1]).get(function(err, res) { 44 | if (err) return cb(err); 45 | 46 | travis.hooks(res.repo && res.repo.id).put({ 47 | hook: {active: true} 48 | 49 | }, function(err, content) { 50 | if (err) return cb(err); 51 | cb(null, content); 52 | }); 53 | }); 54 | }); 55 | }); 56 | } 57 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "enable-travis", 3 | "description": "CLI to enable Travis CI for a node.js project.", 4 | "version": "1.0.0", 5 | "homepage": "https://github.com/jonschlinkert/enable-travis", 6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)", 7 | "repository": "jonschlinkert/enable-travis", 8 | "bugs": { 9 | "url": "https://github.com/jonschlinkert/enable-travis/issues" 10 | }, 11 | "license": "MIT", 12 | "files": [ 13 | "cli.js", 14 | "index.js" 15 | ], 16 | "main": "index.js", 17 | "preferGlobal": true, 18 | "bin": { 19 | "enable-travis": "./cli.js" 20 | }, 21 | "engines": { 22 | "node": ">=4.0" 23 | }, 24 | "scripts": { 25 | "test": "mocha" 26 | }, 27 | "dependencies": { 28 | "data-store": "^1.0.0", 29 | "enquirer": "^1.0.2", 30 | "git-repo-name": "^0.6.0", 31 | "git-user-name": "^1.2.0", 32 | "git-username": "^0.5.0", 33 | "load-pkg": "^3.0.1", 34 | "log-utils": "^0.2.1", 35 | "minimist": "^1.2.0", 36 | "prompt-password": "^1.2.0", 37 | "travis-ci": "^2.1.1" 38 | }, 39 | "keywords": [ 40 | "enable", 41 | "travis" 42 | ], 43 | "verb": { 44 | "related": { 45 | "list": [ 46 | "sync-travis" 47 | ] 48 | }, 49 | "toc": false, 50 | "layout": "default", 51 | "tasks": [ 52 | "readme" 53 | ], 54 | "plugins": [ 55 | "gulp-format-md" 56 | ], 57 | "lint": { 58 | "reflinks": true 59 | }, 60 | "reflinks": [ 61 | "sync-travis", 62 | "travis-ci" 63 | ] 64 | }, 65 | "devDependencies": { 66 | "gulp-format-md": "^1.0.0" 67 | } 68 | } 69 | --------------------------------------------------------------------------------