Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allows seperate prefixTag version sequences #573

Merged
merged 7 commits into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -56,7 +56,7 @@ module.exports = async function standardVersion (argv) {
if (pkg) {
version = pkg.version
} else if (args.gitTagFallback) {
version = await latestSemverTag()
version = await latestSemverTag(args.tagPrefix)
} else {
throw new Error('no package file found')
}
Expand Down
6 changes: 4 additions & 2 deletions 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)
Expand Down
25 changes: 24 additions & 1 deletion test/git.spec.js
Expand Up @@ -66,7 +66,7 @@ function mock ({ bump, changelog, tags }) {
}
}))

mockery.registerMock('git-semver-tags', function (cb) {
mockery.registerMock('git-semver-tags', function (_, cb) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jahead this is looking good to me, but any chance we could add a test that covers the additional functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea mate, I"ll do it tonight.

I was thinking how to test this

Copy link
Contributor Author

@jahead jahead Apr 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcoe Hey so I added some tests here and tested tagPrefix in general, as there didn't seem to be any tests already that I could see.

I'm not overly happy with is this as git-semver-tags actually is the one filtering the tags, and due to the mock we won't know if git-semver-tags changes will break the logic here. But the tests cover the use case in #702

resolve if you're happy

if (tags instanceof Error) cb(tags)
else cb(null, tags || [])
})
Expand Down Expand Up @@ -103,6 +103,29 @@ 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'] })
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 [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 () {
mock({ bump: 'minor', tags: ['v1.0.0'] })
await exec({})
Expand Down