Enable Travis CI builds for one or more repositories.
$ npm install travis-ci-enable
var enable = require( 'travis-ci-enable' );
Enable Travis CI builds for one or more repositories. Each provided repository slug
should obey the format :owner/:repo
.
var repos = [
'math-io/polygamma',
'math-io/gammaln',
'kgryte/utils-deep-set',
'unknown/repo'
];
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
enable( repos, opts, clbk )
function clbk( error, results ) {
if ( error ) {
throw new Error( error.message );
}
console.dir( results );
/* returns
{
"meta": {
"total": 4,
"success": 3,
"failure": 1
},
"data": {
"math-io/polygamma": {
"result": true
},
"math-io/gammaln": {
"result": true
},
"kgryte/utils-deep-set": {
"result": true
}
},
"failures": {
"unknown/repo": "Not Found"
}
}
*/
}
The function
accepts the following options
:
- token: Travis CI access token (required).
- hostname: endpoint hostname. Default:
'api.travis-ci.org'
. - sync:
boolean
indicating whether to sync Travis CI with Github before attempting to enable builds. Default:false
.
To authenticate with Travis CI, set the token
option.
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
enable( repos, opts, clbk );
By default, the function
contacts the Travis CI API for open source. To use a different Travis CI API endpoint, set the hostname
option.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'hostname': 'api.travis-ci.com'
};
enable( repos, opts, clbk );
Travis CI requires a manual sync in order to have the most up-to-date repository information for an authenticated user. Hence, unless a sync is triggered, Travis CI is not aware of repositories created since the last sync. To trigger a sync before attempting to enable, set the sync
option to true
.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'hostname': 'api.travis-ci.com',
'sync': true
};
enable( repos, opts, clbk );
Creates a reusable function
.
var opts = {
'token': 'tkjorjk34ek3nj4!',
'hostname': 'api.travis-ci.com',
'sync': true
};
var run = enable.factory( opts, clbk );
var repos = [ 'math-io/erf', 'math-io/erfc' ];
run( repos );
// Some time later...
repos = [ 'kgryte/utils-copy', 'kgryte/utils-merge' ];
run( repos );
// Some time later...
repos = [ 'dstructs/matrix', 'math-io/evalpoly' ];
run( repos );
// ...
The factory method accepts the same options
as enable()
.
-
If the module encounters an application-level
error
while initially querying an endpoint (e.g., no network connection, malformed request, etc), thaterror
is returned immediately to the providedcallback
. -
If the module encounters a downstream
error
(e.g., timeout, reset connection, etc), thaterror
is included in the returned results under thefailures
field. -
If possible, avoid repeatedly triggering a sync in close succession, as each sync may entail multiple Github API requests, thus affecting a user's Github rate limit. Hence, if an application requires multiple
enable
invocations, separately trigger a sync once, rather than setting thesync
option totrue
.var sync = require( 'travis-ci-sync' ); var factory = require( 'travis-ci-enable' ).factory; var opts = { 'token': 'tkjorjk34ek3nj4!', 'sync': false }; sync( opts, onSync ); function onSync( error ) { var enable; var repos; if ( error ) { throw new Error( error.message ); } enable = factory( opts, onEnable ); repos = [ 'math-io/erf', 'math-io/erfc' ]; enable( repos ); // Next invocation does not trigger a sync... repos = [ 'kgryte/utils-copy', 'kgryte/utils-merge' ]; enable( repos ); } function onEnable( error, results ) { if ( error ) { return console.error( error.message ); } console.dir( results ); }
var enable = require( 'travis-ci-enable' );
var repos = [
'math-io/erf',
'math-io/erfc',
'math-io/erfinv'
];
var opts = {
'token': 'tkjorjk34ek3nj4!'
};
enable( repos, opts, clbk );
function clbk( error, results ) {
if ( error ) {
throw new Error( error.message );
}
console.dir( results );
}
To run the example code from the top-level application directory,
$ node ./examples/index.js
Note: in order to run the example, you will need to obtain an access token and modify the token
option accordingly.
To use the module as a general utility, install the module globally
$ npm install -g travis-ci-enable
Usage: travisenable [options] slug1 slug2 ...
Options:
-h, --help Print this message.
-V, --version Print the package version.
--hostname host Hostname. Default: api.travis-ci.org.
--token token Travis CI access token.
--sync Sync Travis CI with Github.
-
If a
slug
is not provided, the implementation will attempt to infer aslug
by executinggit config remote.origin.url
in the current working directory.
-
In addition to the
token
option, the token may be specified by aTRAVISCI_TOKEN
environment variable. The command-line option always takes precedence. -
If builds for a repository are successfully enabled, results are written to
stdout
. -
If builds for a repository cannot be enabled due to a downstream
error
(failure), the repositoryslug
(and its associatederror
) is written tosterr
. -
Output order is not guaranteed to match input order.
Setting the access token using the command-line option:
$ DEBUG=* travisenable --token <token> math-io/erfinv
# => {...}
Setting the access token using an environment variable:
$ DEBUG=* TRAVISCI_TOKEN=<token> travisenable math-io/erfinv
# => {...}
For local installations, modify the command to point to the local installation directory; e.g.,
$ DEBUG=* ./node_modules/.bin/travisenable --token <token> math-io/erfinv
# => {...}
Or, if you have cloned this repository and run npm install
, modify the command to point to the executable; e.g.,
$ DEBUG=* node ./bin/cli --token <token> math-io/erfinv
# => {...}
This repository uses tape for unit tests. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
This repository uses Testling for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:
$ make test-browsers
To view the tests in a local web browser,
$ make view-browser-tests
Copyright © 2016. Athan Reines.