Skip to content

Commit 823e27f

Browse files
committed
1.1.5
1 parent 7034bd6 commit 823e27f

File tree

6 files changed

+142
-105
lines changed

6 files changed

+142
-105
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to [keepachangelog.com](http://keepachangelog.com).
55

6+
## [1.1.5] - 2015-04-02
7+
* more improvements to CLI style & formatting
8+
* bump `changelog-parser` to 2.x
9+
* bump `standard` to 3.x
10+
* readme updates
11+
612
## [1.1.4] - 2015-04-01
7-
* Improve preview style & formatting ([#15](https://github.com/ngoldman/gh-release/issues/15) & [#24](https://github.com/ngoldman/gh-release/pull/24))
13+
* improve preview style & formatting ([#15](https://github.com/ngoldman/gh-release/issues/15) & [#24](https://github.com/ngoldman/gh-release/pull/24))
814

915
## [1.1.3] - 2015-03-22
1016
* Handle error when release number already exists on github
@@ -63,7 +69,8 @@ This change log adheres to [keepachangelog.com](http://keepachangelog.com).
6369
* define basic node interface
6470
* define basic cli interface
6571

66-
[1.1.3]: https://github.com/ngoldman/gh-release/compare/v1.1.3...v1.1.4
72+
[1.1.5]: https://github.com/ngoldman/gh-release/compare/v1.1.4...v1.1.5
73+
[1.1.4]: https://github.com/ngoldman/gh-release/compare/v1.1.3...v1.1.4
6774
[1.1.3]: https://github.com/ngoldman/gh-release/compare/v1.1.2...v1.1.3
6875
[1.1.2]: https://github.com/ngoldman/gh-release/compare/v1.1.1...v1.1.2
6976
[1.1.1]: https://github.com/ngoldman/gh-release/compare/v1.1.0...v1.1.1

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ Uses the [Github Releases API](https://developer.github.com/v3/repos/releases/)
1010

1111
![gh-release example](demo.gif)
1212

13-
## Usage
13+
## Command-line interface
1414

15-
### CLI
15+
### Install
16+
17+
```
18+
$ npm install gh-release -g
19+
```
20+
21+
### Usage
1622

1723
```
18-
$ npm install -g gh-release
1924
$ gh-release --help
2025
Usage: gh-release [options]
2126
@@ -37,19 +42,18 @@ $ gh-release
3742
Your GitHub username: ngoldman
3843
Your GitHub password: ✔✔✔✔✔✔✔✔
3944
45+
creating release v1.1.2 for ngoldman/gh-release
46+
47+
name: v1.1.2
4048
tag_name: v1.1.2
4149
target_commitish: ffed090688fb1b853aa07a546ac2e3965a02bb1d
42-
name: v1.1.2
43-
body: * add `dry-run` and `workpath` options
44-
* improve change log
45-
owner: ngoldman
46-
repo: gh-release
4750
draft: false
4851
prerelease: false
52+
body: * add `dry-run` and `workpath` options
53+
* improve change log
4954
dryRun: false
50-
workpath: /Users/ng/dev/github/gh-release
5155
52-
? does this look right? (y/N) y
56+
? publish release to github? (y/N) y
5357
https://github.com/ngoldman/gh-release/releases/tag/v1.1.2
5458
```
5559

@@ -61,12 +65,16 @@ Prints release URL to terminal on success.
6165

6266
Saves github API token to `$HOME/.config/gh-release.json` after first authentication.
6367

64-
### Node
68+
## Node
69+
70+
### Install
6571

6672
```
6773
$ npm install gh-release --save-dev
6874
```
6975

76+
### Usage
77+
7078
```js
7179
var ghRelease = require('gh-release')
7280

@@ -116,7 +124,7 @@ All default values taken from `package.json` unless specified otherwise.
116124
| `draft` | publish as draft | false |
117125
| `prerelease` | publish as prerelease | false |
118126

119-
Override defaults with flags ([cli](#cli)) or the `options` object ([node](#node)).
127+
Override defaults with flags (CLI) or the `options` object (node).
120128

121129
## Standards
122130

@@ -129,7 +137,7 @@ All [releases](https://github.com/ngoldman/gh-release/releases) of `gh-release`
129137

130138
## Motivation
131139

132-
There are packages that already do something like this, and they're great, but I want something that does this one thing really well and nothing else, leans heavily on standards in `package.json` and `CHANGELOG.md`, and can work both as a cli tool and programmatically in node.
140+
There are packages that already do something like this, and they're great, but I want something that does this one thing really well and nothing else, leans heavily on standards in `package.json` and `CHANGELOG.md`, and can work both as a CLI tool and programmatically in node.
133141

134142
## Contributing
135143

bin/cli.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ function handleDefaults (err, defaults) {
104104
var options = extend(defaults, argv)
105105

106106
Object.keys(options).forEach(function (key) {
107-
if (whitelist.indexOf(key) === -1)
108-
delete options[key]
107+
if (whitelist.indexOf(key) === -1) delete options[key]
109108
})
110109

111110
ghRelease(options, auth, handleRelease)

index.js

Lines changed: 101 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
module.exports = ghRelease
2+
13
var getDefaults = require(__dirname + '/lib/get-defaults')
24
var extend = require('util')._extend
35
var GHAPI = require('github')
@@ -6,16 +8,15 @@ var wrap = require('word-wrap')
68
var size = require('window-size')
79
var client = new GHAPI({
810
version: '3.0.0',
9-
headers: {
10-
'user-agent': 'gh-release'
11-
}
11+
headers: { 'user-agent': 'gh-release' }
1212
})
1313
var inquirer = require('inquirer')
14+
var columnWidth = 18
1415
var questions = [
1516
{
1617
type: 'confirm',
1718
name: 'confirm',
18-
message: 'does this look right?',
19+
message: 'publish release to github?',
1920
default: false,
2021
validate: function (input) {
2122
if (!input) return false
@@ -24,81 +25,41 @@ var questions = [
2425
}
2526
]
2627

27-
function justify (word) {
28-
var justifiedWord = word + ':'
29-
while (justifiedWord.length < 18) {
30-
justifiedWord += ' '
31-
}
32-
return justifiedWord
33-
}
34-
35-
function indentBody (body) {
36-
var lines = wrap(body, {
37-
indent: '',
38-
width: size.width - 18
39-
})
40-
.split('\n')
41-
.filter(function (line) {
42-
return line !== ''
43-
})
44-
return lines.map(function (line, i) {
45-
if (i === 0) {
46-
return {column1: justify('body'), column2: line}
47-
} else {
48-
return {column1: ' ', column2: line}
49-
}
50-
})
51-
}
28+
function ghRelease (options, auth, callback) {
29+
var hasToken = auth && auth.token
30+
var hasUser = auth && auth.username
31+
var hasPass = auth && auth.password
32+
var hasBasic = hasUser && hasPass
33+
var authOptions
5234

53-
function formatOptions (options) {
54-
var prettyOptions = []
55-
var keys = Object.keys(options)
56-
keys.forEach(function (key) {
57-
var column1 = justify(key)
58-
if (key === 'body') {
59-
var body = indentBody(options.body)
60-
prettyOptions.push.apply(prettyOptions, body)
61-
} else {
62-
prettyOptions.push({column1: column1, column2: options[key]})
63-
}
64-
})
65-
return prettyOptions
66-
}
35+
if (!hasToken && !hasBasic) return callback(new Error('missing auth info'))
6736

68-
function ghRelease (options, auth, callback) {
69-
if (auth && auth.token) {
70-
client.authenticate({
37+
if (hasToken) {
38+
authOptions = {
7139
type: 'oauth',
7240
token: auth.token
73-
})
74-
} else if (auth && auth.username && auth.password) {
75-
client.authenticate({
41+
}
42+
} else {
43+
authOptions = {
7644
type: 'basic',
7745
username: auth.username,
7846
password: auth.password
79-
})
80-
} else {
81-
return callback(new Error('missing auth info'))
47+
}
8248
}
8349

50+
client.authenticate(authOptions)
51+
8452
getDefaults(options.workpath, function (err, defaults) {
8553
if (err) return callback(err)
8654

8755
var releaseOptions = extend(defaults, options || {})
88-
var prettyOptions = formatOptions(releaseOptions)
8956

90-
prettyOptions.forEach(function (option) {
91-
console.log(chalk.blue(option.column1) + chalk.green(option.column2))
92-
})
93-
console.log('')
57+
showPreview(releaseOptions)
9458

9559
if (options.dryRun) process.exit(0)
9660

9761
inquirer.prompt(questions, function (answers) {
98-
if (!answers.confirm) {
99-
console.log('release canceled')
100-
process.exit(0)
101-
}
62+
if (!answers.confirm) return process.exit(0)
10263

10364
var checkCommitForm = {
10465
user: releaseOptions.owner,
@@ -111,26 +72,88 @@ function ghRelease (options, auth, callback) {
11172
console.log('Couldn\'t find the target commit on GitHub.')
11273
console.log('Make sure you\'ve pushed everything up to ' + releaseOptions.owner + '/' + releaseOptions.repo + ' and try again')
11374
console.log('Target commit: ' + releaseOptions.target_commitish)
114-
process.exit(1)
115-
} else {
116-
client.releases.createRelease(releaseOptions, function (err, res) {
117-
if (err) {
118-
var message = JSON.parse(err.message)
119-
var tagExists = (message.errors[0].code === 'already_exists')
120-
if (err.code === 422 && tagExists) {
121-
console.log('A release already exists for the tag ' + releaseOptions.tag_name)
122-
console.log('Try bumping the version in your package.json.\nThen push to ' + releaseOptions.owner + '/' + releaseOptions.repo + ' and try again.')
123-
} else {
124-
console.error(err)
125-
}
126-
process.exit(1)
127-
}
128-
callback(null, res)
129-
})
75+
return process.exit(1)
13076
}
77+
78+
client.releases.createRelease(releaseOptions, function (err, res) {
79+
if (err) {
80+
var message = JSON.parse(err.message)
81+
var tagExists = (message.errors[0].code === 'already_exists')
82+
if (err.code === 422 && tagExists) {
83+
console.log('A release already exists for the tag ' + releaseOptions.tag_name)
84+
console.log('Try bumping the version in your package.json.\nThen push to ' + releaseOptions.owner + '/' + releaseOptions.repo + ' and try again.')
85+
} else {
86+
console.error(err)
87+
}
88+
return process.exit(1)
89+
}
90+
91+
callback(null, res)
92+
})
13193
})
13294
})
13395
})
13496
}
13597

136-
module.exports = ghRelease
98+
function showPreview (opts) {
99+
var intro = '\ncreating release ' + chalk.bold(opts.tag_name) +
100+
' for ' + chalk.bold(opts.owner + '/' + opts.repo) + '\n'
101+
var prettyOptions = formatOptions(opts)
102+
103+
console.log(intro)
104+
105+
prettyOptions.forEach(function (option) {
106+
console.log(chalk.cyan(option.column1) + option.column2)
107+
})
108+
109+
console.log('')
110+
}
111+
112+
function formatOptions (options) {
113+
var opts = extend({}, options)
114+
115+
delete opts.owner
116+
delete opts.repo
117+
delete opts.dryRun
118+
delete opts.workpath
119+
120+
var prettyOptions = []
121+
var keys = Object.keys(opts)
122+
123+
keys.forEach(function (key) {
124+
var column1 = justify(key)
125+
if (key === 'body') {
126+
var body = indentBody(opts.body)
127+
prettyOptions.push.apply(prettyOptions, body)
128+
} else {
129+
prettyOptions.push({column1: column1, column2: opts[key]})
130+
}
131+
})
132+
133+
return prettyOptions
134+
}
135+
136+
function indentBody (body) {
137+
var lines = wrap(body, {
138+
indent: '',
139+
width: size.width - columnWidth
140+
})
141+
.split('\n')
142+
.filter(function (line) {
143+
return line !== ''
144+
})
145+
146+
return lines.map(function (line, i) {
147+
if (i === 0) {
148+
return { column1: justify('body'), column2: line }
149+
} else {
150+
return { column1: new Array(columnWidth).join(' '), column2: line }
151+
}
152+
})
153+
}
154+
155+
function justify (word) {
156+
var justifiedWord = word + ':'
157+
while (justifiedWord.length < columnWidth) justifiedWord += ' '
158+
return justifiedWord
159+
}

lib/get-defaults.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ module.exports = function getDefaults (workPath, callback) {
2828
var version = pkg.version ? 'v' + pkg.version : null
2929

3030
callback(null, {
31-
tag_name: version,
32-
target_commitish: commit,
33-
name: version,
34-
body: log.body,
3531
owner: owner,
3632
repo: repo,
37-
draft: false,
38-
prerelease: false,
3933
dryRun: false,
40-
workpath: process.cwd()
34+
workpath: process.cwd(),
35+
body: log.body,
36+
prerelease: false,
37+
draft: false,
38+
target_commitish: commit,
39+
tag_name: version,
40+
name: version
4141
})
4242
})
4343
}

0 commit comments

Comments
 (0)