diff --git a/CHANGELOG.md b/CHANGELOG.md index efead78..a78339d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,13 @@ Project versioning adheres to [Semantic Versioning](http://semver.org/). Commit convention is based on [Conventional Commits](http://conventionalcommits.org). Change log format is based on [Keep a Changelog](http://keepachangelog.com/). +## Unreleased + +### Additions + +- `--yes` CLI option to skip the release confirmation prompt +- Support for reading the GitHub access token from the `GH_RELEASE_GITHUB_API_TOKEN` environment variable + ## [3.2.3](https://github.com/hypermodules/gh-release/compare/v3.2.2...v3.2.3) - 2018-08-30 ### Fixes diff --git a/README.md b/README.md index 47179aa..69a80b1 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Expects a `package.json` and `CHANGELOG.md` in the working directory. Prints release URL to `stdout` on success. -Uses [`ghauth`](https://github.com/rvagg/ghauth) for authentication with Github. A Github API OAuth token is saved to the `gh-release` config directory after the first time authenticating. Note that the config directory is determined by [`application-config`](https://github.com/LinusU/node-application-config) and is OS-specific. +Uses [`ghauth`](https://github.com/rvagg/ghauth) for authentication with Github. A Github API OAuth token is saved to the `gh-release` config directory after the first time authenticating. Note that the config directory is determined by [`application-config`](https://github.com/LinusU/node-application-config) and is OS-specific. gh-release will alternatively use the token specified in the `GH_RELEASE_GITHUB_API_TOKEN` environment variable if it exists. This allows it to be used in continuous deployment systems, which can inject different GitHub API tokens depending on the location of the project. Get usage info by running with `--help` or `-h`. @@ -82,6 +82,7 @@ Options: -e, --endpoint GitHub API endpoint URL [default: "https://api.github.com"] -a, --assets comma-delimited list of assets to upload [default: false] --dry-run dry run (stops before release step) [default: false] + -y, --yes bypass confirmation prompt for release [default: false] -h, --help Show help -v, --version Show version number ``` diff --git a/bin/cli.js b/bin/cli.js index f9c8f47..b8b3039 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -47,9 +47,18 @@ if (argv.assets) { }) } -ghauth(ghauthOpts, function (err, auth) { - if (err) return handleError(err) +if (process.env.GH_RELEASE_GITHUB_API_TOKEN) { + releaseWithAuth({ + token: process.env.GH_RELEASE_GITHUB_API_TOKEN + }) +} else { + ghauth(ghauthOpts, function (err, auth) { + if (err) return handleError(err) + releaseWithAuth(auth) + }) +} +function releaseWithAuth (auth) { var options = {} options.auth = auth options.cli = true @@ -83,6 +92,9 @@ ghauth(ghauthOpts, function (err, auth) { if (options.dryRun) process.exit(0) + if (options.yes) { + return performRelease(options) + } // confirm & release var confirmation = [{ @@ -98,30 +110,33 @@ ghauth(ghauthOpts, function (err, auth) { inquirer.prompt(confirmation, function (answers) { if (!answers.confirm) return process.exit(1) + performRelease(options) + }) + }) +} - // pass options to api +function performRelease (options) { + // pass options to api - ghRelease(options, function ghReleaseCallback (err, result) { - // handle errors - if (err) return handleError(err) + ghRelease(options, function ghReleaseCallback (err, result) { + // handle errors + if (err) return handleError(err) - if (result.message === 'Moved Permanently') { - console.error('repository url in package.json is out of date and requires a redirect') - process.exit(1) - } + if (result.message === 'Moved Permanently') { + console.error('repository url in package.json is out of date and requires a redirect') + process.exit(1) + } - if (!result || !result.html_url) { - console.error('missing result info') - process.exit(1) - } + if (!result || !result.html_url) { + console.error('missing result info') + process.exit(1) + } - // log release url & exit 0 - console.log(result.html_url) - process.exit(0) - }) - }) + // log release url & exit 0 + console.log(result.html_url) + process.exit(0) }) -}) +} function handleError (err) { var msg = err.msg || err diff --git a/bin/lib/get-defaults.js b/bin/lib/get-defaults.js index 2330105..22901fd 100644 --- a/bin/lib/get-defaults.js +++ b/bin/lib/get-defaults.js @@ -51,6 +51,7 @@ function getDefaults (workPath, isEnterprise, callback) { owner: owner, repo: repo, dryRun: false, + yes: false, endpoint: 'https://api.github.com', workpath: process.cwd(), prerelease: false, diff --git a/bin/lib/preview.js b/bin/lib/preview.js index 7a60d9b..6e1dca0 100644 --- a/bin/lib/preview.js +++ b/bin/lib/preview.js @@ -24,6 +24,7 @@ function formatOptions (options) { delete copy.owner delete copy.repo delete copy.dryRun + delete copy.yes delete copy.workpath var keys = Object.keys(copy).reverse() diff --git a/bin/lib/yargs.js b/bin/lib/yargs.js index b1a3294..5a0893b 100644 --- a/bin/lib/yargs.js +++ b/bin/lib/yargs.js @@ -66,6 +66,12 @@ module.exports = require('yargs') type: 'boolean', default: false, describe: 'dry run (stops before release step)' + }, + 'y': { + alias: 'yes', + type: 'boolean', + default: false, + describe: 'bypass confirmation prompt for release' } }) .example('$0 -n v' + version + ' -c master -d', 'create a draft release with title v' + version + ' tagged at HEAD of master') diff --git a/index.js b/index.js index 5511896..b8df44a 100644 --- a/index.js +++ b/index.js @@ -18,6 +18,7 @@ var OPTIONS = { valid: [], defaults: { 'dryRun': false, + 'yes': false, 'draft': false, 'endpoint': 'https://api.github.com', 'prerelease': false, @@ -32,6 +33,7 @@ var OPTIONS = { 'tag_name', 'name', 'dryRun', + 'yes', 'draft', 'endpoint', 'prerelease',