Skip to content

Commit 0de3ddf

Browse files
authored
Merge branch 'master' into master
2 parents 09c2045 + 0330f1b commit 0de3ddf

8 files changed

Lines changed: 139 additions & 23 deletions

File tree

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.nyc_output/
2+
/coverage/
13
/node_modules/
2-
token
3-
tmp
4+
yarn-error.log

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ Default: `1`
120120

121121
How many releases of changelog you want to generate. It counts from the latest semver tag. Useful when you forgot to generate any previous releases. Set to `0` to regenerate all.
122122

123+
##### name
124+
125+
Default: same as version tag
126+
127+
Name that should be applied to the release on GitHub.
128+
129+
##### targetCommitish
130+
131+
Default: `undefined` (uses the tag to determine commit)
132+
133+
Specific `target_commitish` in GitHub release
134+
123135
#### gitRawCommitsOpts
124136

125137
##### from

cli.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ conventionalGithubReleaser({
107107
process.exit(1);
108108
}
109109

110+
if (0 === data.length) {
111+
if (flags.verbose) {
112+
console.log('No GitHub releases created because no git tags available to work with.');
113+
}
114+
115+
process.exit(0);
116+
}
117+
110118
var allRejected = true;
111119

112120
for (var i = data.length - 1; i >= 0 ; i--) {

index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
'use strict';
22
var assign = require('object-assign');
33
var conventionalChangelog = require('conventional-changelog');
4-
var dateFormat = require('dateformat');
54
var Github = require('github');
65
var gitSemverTags = require('git-semver-tags');
76
var merge = require('lodash.merge');
87
var Q = require('q');
98
var semver = require('semver');
109
var through = require('through2');
10+
var transform = require('./lib/transform');
1111

1212
var github = new Github({
1313
version: '3.0.0'
@@ -40,20 +40,7 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
4040
writerOpts = changelogArgs[4];
4141

4242
changelogOpts = merge({
43-
transform: function(chunk, cb) {
44-
if (typeof chunk.gitTags === 'string') {
45-
var match = /tag:\s*(.+?)[,\)]/gi.exec(chunk.gitTags);
46-
if (match) {
47-
chunk.version = match[1];
48-
}
49-
}
50-
51-
if (chunk.committerDate) {
52-
chunk.committerDate = dateFormat(chunk.committerDate, 'yyyy-mm-dd', true);
53-
}
54-
55-
cb(null, chunk);
56-
},
43+
transform: transform,
5744
releaseCount: 1
5845
}, changelogOpts);
5946

@@ -75,7 +62,7 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
7562
if (releaseCount !== 0) {
7663
gitRawCommitsOpts = assign({
7764
from: tags[releaseCount]
78-
});
65+
}, gitRawCommitsOpts);
7966
}
8067

8168
gitRawCommitsOpts.to = gitRawCommitsOpts.to || tags[0];
@@ -104,6 +91,8 @@ function conventionalGithubReleaser(auth, changelogOpts, context, gitRawCommitsO
10491
body: chunk.log,
10592
prerelease: prerelease,
10693
draft: draft
94+
target_commitish: changelogOpts.targetCommitish,
95+
name: changelogOpts.name || version
10796
// jscs:enable
10897
});
10998

lib/transform.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
3+
var dateFormat = require('dateformat');
4+
var findVersions = require('find-versions');
5+
6+
function transform(chunk, cb) {
7+
if (typeof chunk.gitTags === 'string') {
8+
chunk.version = findVersions(chunk.gitTags)[0];
9+
}
10+
11+
if (chunk.committerDate) {
12+
chunk.committerDate = dateFormat(chunk.committerDate, 'yyyy-mm-dd', true);
13+
}
14+
15+
cb(null, chunk);
16+
}
17+
18+
module.exports = transform;

lib/transform.spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'use strict';
2+
3+
// jshint expr: true
4+
5+
var chai = require('chai');
6+
var transform = require('./transform');
7+
8+
var expect = chai.expect;
9+
10+
describe('transform', function() {
11+
beforeEach(function() {
12+
this.chunk = {
13+
gitTags: '',
14+
};
15+
});
16+
17+
it('should skip semantic version matching when gitTags isn\'t a string', function(done) {
18+
this.chunk.gitTags = undefined;
19+
20+
transform(this.chunk, function(err, chunk) {
21+
expect(chunk.version).to.be.undefined;
22+
done();
23+
});
24+
});
25+
26+
it('should have no version when there are no tags', function(done) {
27+
transform(this.chunk, function(err, chunk) {
28+
expect(chunk.version).to.be.undefined;
29+
done();
30+
});
31+
});
32+
33+
it('should not match invalid semantic version tag', function(done) {
34+
this.chunk.gitTags = ' tag: release-18';
35+
36+
transform(this.chunk, function(err, chunk) {
37+
expect(chunk.version).to.be.undefined;
38+
done();
39+
});
40+
});
41+
42+
it('should match valid semantic version tag', function(done) {
43+
this.chunk.gitTags = ' tag: release-18, tag: 1.1.20';
44+
45+
transform(this.chunk, function(err, chunk) {
46+
expect(chunk.version).to.equal('1.1.20');
47+
done();
48+
});
49+
});
50+
});

package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "conventional-github-releaser",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"description": "Make a new GitHub release from git metadata",
55
"homepage": "https://github.com/conventional-changelog/conventional-github-releaser",
66
"author": {
@@ -28,8 +28,9 @@
2828
"dependencies": {
2929
"conventional-changelog": "^1.1.0",
3030
"dateformat": "^1.0.11",
31+
"find-versions": "^2.0.0",
3132
"git-semver-tags": "^1.0.0",
32-
"github": "^2.0.0",
33+
"github": "^0.2.4",
3334
"lodash.merge": "^4.0.2",
3435
"meow": "^3.3.0",
3536
"object-assign": "^4.0.1",
@@ -43,15 +44,17 @@
4344
"coveralls": "^2.11.2",
4445
"github-remove-all-releases": "^1.0.0",
4546
"istanbul": "^0.4.1",
46-
"jscs": "^3.0.5",
47+
"jscs": "^2.0.0",
4748
"jshint": "^2.9.1",
4849
"mocha": "*",
49-
"shelljs": "^0.7.0"
50+
"nyc": "^10.3.2",
51+
"shelljs": "^0.6.0"
5052
},
5153
"scripts": {
5254
"coverage": "istanbul cover _mocha -- -R spec --timeout 50000 && rm -rf ./coverage",
5355
"lint": "jshint *.js test --exclude node_modules && jscs *.js test",
54-
"test": "npm run-script lint && mocha --timeout 50000"
56+
"formertest": "npm run-script lint && mocha --timeout 50000",
57+
"test": "jshint lib/ && jscs lib/ && nyc --all --cache --include=lib/ --exclude=lib/**/*.spec.js --reporter=lcov --reporter=text mocha --check-leaks --full-trace --globals __core-js_shared__,__coverage__,YamlEscaper --inline-diffs --no-exit --recursive --reporter=progress --retries 1 lib/**/*.spec.js"
5558
},
5659
"bin": {
5760
"conventional-github-releaser": "cli.js"

test/cli.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
var expect = require('chai').expect;
33
var fs = require('fs');
4+
var Q = require('q');
45
var githubRemoveAllReleases = require('github-remove-all-releases');
56
var shell = require('shelljs');
67
var spawn = require('child_process').spawn;
@@ -64,6 +65,40 @@ describe('cli', function() {
6465
});
6566
});
6667

68+
it('should work with no releases', function(done) {
69+
Q.Promise(function(resolve, reject) {
70+
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
71+
stdio: [process.stdin, null, null]
72+
});
73+
74+
cp.on('error', function(code) {
75+
reject('Process exits with code ' + code);
76+
});
77+
78+
cp.on('close', function(code) {
79+
expect(code).to.equal(0);
80+
81+
resolve();
82+
});
83+
}).then(function() {
84+
// we call it a second time, because there no tags are left to create a release from
85+
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token, '-v'], {
86+
stdio: [process.stdin, null, null]
87+
});
88+
89+
cp.on('error', function(code) {
90+
done('Process exits with code ' + code);
91+
});
92+
93+
cp.on('close', function(code) {
94+
// this time we also expect the cli to exit with code 0 due to #17
95+
expect(code).to.equal(0);
96+
97+
done();
98+
});
99+
});
100+
});
101+
67102
it('should print out error message and exit with `1` if all results error', function(done) {
68103
var cp = spawn(cliPath, ['--pkg', __dirname + '/fixtures/_package.json', '-t', AUTH.token], {
69104
stdio: [process.stdin, null, null]

0 commit comments

Comments
 (0)