Skip to content

Commit

Permalink
add GH_RELEASE_GITHUB_API_TOKEN & yes flag (#76)
Browse files Browse the repository at this point in the history
* Support non-interactive continuous-delivery system use cases

* Fix changelog entry for noconfirm

* Switch to --yes for skipping confirmation prompt

* Switch to --yes for skipping confirmation prompt
  • Loading branch information
Ted Janeczko authored and ungoldman committed Sep 4, 2018
1 parent fbb5f20 commit 54a24e9
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 21 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand All @@ -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
```
Expand Down
55 changes: 35 additions & 20 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [{
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions bin/lib/get-defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions bin/lib/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions bin/lib/yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var OPTIONS = {
valid: [],
defaults: {
'dryRun': false,
'yes': false,
'draft': false,
'endpoint': 'https://api.github.com',
'prerelease': false,
Expand All @@ -32,6 +33,7 @@ var OPTIONS = {
'tag_name',
'name',
'dryRun',
'yes',
'draft',
'endpoint',
'prerelease',
Expand Down

0 comments on commit 54a24e9

Please sign in to comment.