Skip to content

Commit

Permalink
fix(transform): don't remove 'v' from tag
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hutson committed Jun 2, 2017
1 parent 7427b9b commit 1b6a68c
Show file tree
Hide file tree
Showing 4 changed files with 2,420 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"dependencies": {
"conventional-changelog": "^1.1.0",
"dateformat": "^1.0.11",
"find-versions": "^2.0.0",
"git-semver-tags": "^1.0.0",
"github": "^0.2.4",
"lodash.merge": "^4.0.2",
"meow": "^3.3.0",
"object-assign": "^4.0.1",
"q": "^1.4.1",
"semver": "^5.0.1",
"semver-regex": "^1.0.0",
"through2": "^2.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/transform.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

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

function transform(chunk, cb) {
if (typeof chunk.gitTags === 'string') {
chunk.version = findVersions(chunk.gitTags)[0];
chunk.version = (chunk.gitTags.match(semverRegex()) || [])[0];
}

if (chunk.committerDate) {
Expand Down
49 changes: 47 additions & 2 deletions src/transform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ var transform = require('./transform');

var expect = chai.expect;

/*
The contents of `gitTags` is generated by the `git-raw-commits` package, which runs the following command:
git log --format=%B%n-hash-%n%H%n-gitTags-%n%d%n-committerDate-%n%ci
That command returns a list of log entries with output in the following form per commit:
-hash-
e26c9a71a638ef9d4e12c2512fcdf813399559a1
-gitTags-
(tag: 1.1.8)
-committerDate-
2017-05-29 13:42:41 -0500
1.1.8
The value of `gitTags` is the line between `-gitTags-` and `-committerDate-`.
*/

describe('transform', function() {
beforeEach(function() {
this.chunk = {
Expand All @@ -31,7 +49,7 @@ describe('transform', function() {
});

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

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

it('should match valid semantic version tag', function(done) {
this.chunk.gitTags = ' tag: release-18, tag: 1.1.20';
this.chunk.gitTags = ' (tag: 1.1.20)';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.equal('1.1.20');
done();
});
});

it('should match valid semantic version tag containing a leading `v`', function(done) {
this.chunk.gitTags = ' (tag: v1.1.20)';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.equal('v1.1.20');
done();
});
});

it('should find valid semantic version tag out of many tags', function(done) {
this.chunk.gitTags = ' (HEAD -> master, tag: something, tag: 1.1.20, origin/master, origin/HEAD)';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.equal('1.1.20');
done();
});
});

it('should match first semantic version tag when there are multiple valid tags', function(done) {
this.chunk.gitTags = ' (tag: 1.1.19, tag: 1.1.20)';

transform(this.chunk, function(err, chunk) {
expect(chunk.version).to.equal('1.1.19');
done();
});
});
});
Loading

0 comments on commit 1b6a68c

Please sign in to comment.