From c8016dd82408b291b7e1550059e6de4f1d1a6c07 Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Fri, 17 Apr 2020 21:29:45 +1000 Subject: [PATCH 1/6] feat: allows per prefixTag version sequences --- index.js | 2 +- lib/latest-semver-tag.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 74de6e031..700591363 100755 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ module.exports = function standardVersion (argv) { return Promise.resolve() .then(() => { if (!pkg && args.gitTagFallback) { - return latestSemverTag() + return latestSemverTag(args.tagPrefix) } else if (!pkg) { throw new Error('no package file found') } else { diff --git a/lib/latest-semver-tag.js b/lib/latest-semver-tag.js index 7c63ec42a..eec93af2b 100644 --- a/lib/latest-semver-tag.js +++ b/lib/latest-semver-tag.js @@ -1,11 +1,13 @@ const gitSemverTags = require('git-semver-tags') const semver = require('semver') -module.exports = function () { +module.exports = function (tagPrefix = undefined) { return new Promise((resolve, reject) => { - gitSemverTags(function (err, tags) { + gitSemverTags({ tagPrefix }, function (err, tags) { if (err) return reject(err) else if (!tags.length) return resolve('1.0.0') + // Respect tagPrefix + tags = tags.map(tag => tag.replace(new RegExp('^' + tagPrefix), '')) // ensure that the largest semver tag is at the head. tags = tags.map(tag => { return semver.clean(tag) }) tags.sort(semver.rcompare) From 1c93d7f146d5f6488fa22abd5669344156bc3ae4 Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Sun, 4 Apr 2021 15:35:03 +1000 Subject: [PATCH 2/6] fixed tests --- test/git.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/git.spec.js b/test/git.spec.js index 448937286..394d81934 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -66,7 +66,7 @@ function mock ({ bump, changelog, tags }) { } })) - mockery.registerMock('git-semver-tags', function (cb) { + mockery.registerMock('git-semver-tags', function (_, cb) { if (tags instanceof Error) cb(tags) else cb(null, tags || []) }) From 487c51f71f1dcd217236d6a86635a5f94e4937ba Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Tue, 6 Apr 2021 21:38:28 +1000 Subject: [PATCH 3/6] added tests --- test/git.spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/git.spec.js b/test/git.spec.js index 394d81934..4aad8ff49 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -103,6 +103,22 @@ describe('git', function () { } }) + describe('tagPrefix', () => { + it('will add prefix onto tag based on version from package', async function () { + writePackageJson('1.2.0') + mock({ bump: 'minor', tags: ['p-v1.2.0'] }) + await exec('--tag-prefix p-v') + shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/) + }) + + it('will add prefix onto tag via when gitTagFallback is true and no package', async function () { + shell.rm('package.json') + mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] }) + await exec('--tag-prefix android/production/v') + shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/) + }) + }) + it('formats the commit and tag messages appropriately', async function () { mock({ bump: 'minor', tags: ['v1.0.0'] }) await exec({}) From 3f0637429ca7efc458317bffa06106ec1a8bc96d Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Tue, 6 Apr 2021 21:44:55 +1000 Subject: [PATCH 4/6] added options test --- test/git.spec.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/git.spec.js b/test/git.spec.js index 4aad8ff49..c0d33a973 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -111,12 +111,18 @@ describe('git', function () { shell.exec('git tag').stdout.should.match(/p-v1\.3\.0/) }) - it('will add prefix onto tag via when gitTagFallback is true and no package', async function () { + it('will add prefix onto tag via when gitTagFallback is true and no package [cli]', async function () { shell.rm('package.json') mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] }) await exec('--tag-prefix android/production/v') shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/) }) + + it('will add prefix onto tag via when gitTagFallback is true and no package [options]', async function () { + mock({ bump: 'minor', tags: ['android/production/v1.2.0', 'android/production/v1.0.0'] }) + await exec({ tagPrefix: 'android/production/v', packageFiles: [] }) + shell.exec('git tag').stdout.should.match(/android\/production\/v1\.3\.0/) + }) }) it('formats the commit and tag messages appropriately', async function () { From 6965d82328d20ce0fb54a7013d060e65a256754b Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Tue, 6 Apr 2021 21:51:53 +1000 Subject: [PATCH 5/6] added a todo --- test/git.spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/git.spec.js b/test/git.spec.js index c0d33a973..a1766085e 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -104,6 +104,7 @@ describe('git', function () { }) describe('tagPrefix', () => { + //TODO: Use unmocked git-semver-tags and stage a git environment it('will add prefix onto tag based on version from package', async function () { writePackageJson('1.2.0') mock({ bump: 'minor', tags: ['p-v1.2.0'] }) From d4dc1aaa032d2980ba0d164a204a9b58774ef24c Mon Sep 17 00:00:00 2001 From: Joshua Head Date: Tue, 6 Apr 2021 22:01:14 +1000 Subject: [PATCH 6/6] fixed lint --- test/git.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/git.spec.js b/test/git.spec.js index a1766085e..dfa9dbb11 100644 --- a/test/git.spec.js +++ b/test/git.spec.js @@ -104,7 +104,7 @@ describe('git', function () { }) describe('tagPrefix', () => { - //TODO: Use unmocked git-semver-tags and stage a git environment + // TODO: Use unmocked git-semver-tags and stage a git environment it('will add prefix onto tag based on version from package', async function () { writePackageJson('1.2.0') mock({ bump: 'minor', tags: ['p-v1.2.0'] })