Skip to content

Commit 1b6a68c

Browse files
committed
fix(transform): don't remove 'v' from tag
Don't remove the leading `v` from a git tag found to be a semantically valid version tag. Previous behavior was based on a third-party package that removed the leading `v` in front of a semantically valid version tag. Though the behavior was correct for that package, we need to preserve the leading `v` for the purpose of publishing. If the tag has a leading `v`, perhaps because the user has specifically tagged their repository using a leading `v`, they likely expect that `v` to be used as the tag on GitHub, and as the name of the GitHub release page associated with that tag. Therefore we must preserve the leading `v` in all semantically valid version tags. Closes #44
1 parent 7427b9b commit 1b6a68c

File tree

4 files changed

+2420
-5
lines changed

4 files changed

+2420
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@
3939
"dependencies": {
4040
"conventional-changelog": "^1.1.0",
4141
"dateformat": "^1.0.11",
42-
"find-versions": "^2.0.0",
4342
"git-semver-tags": "^1.0.0",
4443
"github": "^0.2.4",
4544
"lodash.merge": "^4.0.2",
4645
"meow": "^3.3.0",
4746
"object-assign": "^4.0.1",
4847
"q": "^1.4.1",
4948
"semver": "^5.0.1",
49+
"semver-regex": "^1.0.0",
5050
"through2": "^2.0.0"
5151
},
5252
"devDependencies": {

src/transform.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
var dateFormat = require('dateformat');
4-
var findVersions = require('find-versions');
4+
var semverRegex = require('semver-regex');
55

66
function transform(chunk, cb) {
77
if (typeof chunk.gitTags === 'string') {
8-
chunk.version = findVersions(chunk.gitTags)[0];
8+
chunk.version = (chunk.gitTags.match(semverRegex()) || [])[0];
99
}
1010

1111
if (chunk.committerDate) {

src/transform.spec.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ var transform = require('./transform');
77

88
var expect = chai.expect;
99

10+
/*
11+
The contents of `gitTags` is generated by the `git-raw-commits` package, which runs the following command:
12+
13+
git log --format=%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci
14+
15+
That command returns a list of log entries with output in the following form per commit:
16+
17+
-hash-
18+
e26c9a71a638ef9d4e12c2512fcdf813399559a1
19+
-gitTags-
20+
(tag: 1.1.8)
21+
-committerDate-
22+
2017-05-29 13:42:41 -0500
23+
1.1.8
24+
25+
The value of `gitTags` is the line between `-gitTags-` and `-committerDate-`.
26+
*/
27+
1028
describe('transform', function() {
1129
beforeEach(function() {
1230
this.chunk = {
@@ -31,7 +49,7 @@ describe('transform', function() {
3149
});
3250

3351
it('should not match invalid semantic version tag', function(done) {
34-
this.chunk.gitTags = ' tag: release-18';
52+
this.chunk.gitTags = ' (tag: release-18)';
3553

3654
transform(this.chunk, function(err, chunk) {
3755
expect(chunk.version).to.be.undefined;
@@ -40,11 +58,38 @@ describe('transform', function() {
4058
});
4159

4260
it('should match valid semantic version tag', function(done) {
43-
this.chunk.gitTags = ' tag: release-18, tag: 1.1.20';
61+
this.chunk.gitTags = ' (tag: 1.1.20)';
62+
63+
transform(this.chunk, function(err, chunk) {
64+
expect(chunk.version).to.equal('1.1.20');
65+
done();
66+
});
67+
});
68+
69+
it('should match valid semantic version tag containing a leading `v`', function(done) {
70+
this.chunk.gitTags = ' (tag: v1.1.20)';
71+
72+
transform(this.chunk, function(err, chunk) {
73+
expect(chunk.version).to.equal('v1.1.20');
74+
done();
75+
});
76+
});
77+
78+
it('should find valid semantic version tag out of many tags', function(done) {
79+
this.chunk.gitTags = ' (HEAD -> master, tag: something, tag: 1.1.20, origin/master, origin/HEAD)';
4480

4581
transform(this.chunk, function(err, chunk) {
4682
expect(chunk.version).to.equal('1.1.20');
4783
done();
4884
});
4985
});
86+
87+
it('should match first semantic version tag when there are multiple valid tags', function(done) {
88+
this.chunk.gitTags = ' (tag: 1.1.19, tag: 1.1.20)';
89+
90+
transform(this.chunk, function(err, chunk) {
91+
expect(chunk.version).to.equal('1.1.19');
92+
done();
93+
});
94+
});
5095
});

0 commit comments

Comments
 (0)