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

Provide sane defaults if we have no prior releases #1067

Merged
merged 3 commits into from Feb 13, 2022
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
47 changes: 46 additions & 1 deletion dist/index.js
Expand Up @@ -129872,6 +129872,50 @@ const splitSemVersion = (input, versionKey = 'version') => {
}
}

const defaultVersionInfo = {
$NEXT_MAJOR_VERSION: {
version: '1.0.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'major',
$MAJOR: 1,
$MINOR: 0,
$PATCH: 0,
},
$NEXT_MINOR_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'minor',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$NEXT_PATCH_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$INPUT_VERSION: null,
$RESOLVED_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
}

const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }),
Expand Down Expand Up @@ -129965,7 +130009,7 @@ const getVersionInfo = (
inputVersion = coerceVersion(inputVersion)

if (!version && !inputVersion) {
return
return defaultVersionInfo
}

return {
Expand All @@ -129979,6 +130023,7 @@ const getVersionInfo = (
}

exports.getVersionInfo = getVersionInfo
exports.defaultVersionInfo = defaultVersionInfo


/***/ }),
Expand Down
47 changes: 46 additions & 1 deletion lib/versions.js
Expand Up @@ -19,6 +19,50 @@ const splitSemVersion = (input, versionKey = 'version') => {
}
}

const defaultVersionInfo = {
$NEXT_MAJOR_VERSION: {
version: '1.0.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'major',
$MAJOR: 1,
$MINOR: 0,
$PATCH: 0,
},
$NEXT_MINOR_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'minor',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$NEXT_PATCH_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
$INPUT_VERSION: null,
$RESOLVED_VERSION: {
version: '0.1.0',
template: '$MAJOR.$MINOR.$PATCH',
inputVersion: null,
versionKeyIncrement: 'patch',
inc: 'patch',
$MAJOR: 0,
$MINOR: 1,
$PATCH: 0,
},
}

const getTemplatableVersion = (input) => {
const templatableVersion = {
$NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }),
Expand Down Expand Up @@ -112,7 +156,7 @@ const getVersionInfo = (
inputVersion = coerceVersion(inputVersion)

if (!version && !inputVersion) {
return
return defaultVersionInfo
}

return {
Expand All @@ -126,3 +170,4 @@ const getVersionInfo = (
}

exports.getVersionInfo = getVersionInfo
exports.defaultVersionInfo = defaultVersionInfo
6 changes: 3 additions & 3 deletions test/index.test.js
Expand Up @@ -2620,7 +2620,7 @@ describe('release-drafter', () => {
})

describe('without previous releases, no overrides', () => {
it('resolves to the calculated version, which will be empty', async () => {
it('resolves to the calculated version, which will be default', async () => {
getConfigMock('config-with-resolved-version-template.yml')

nock('https://api.github.com')
Expand Down Expand Up @@ -2651,9 +2651,9 @@ describe('release-drafter', () => {

",
"draft": true,
"name": "",
"name": "v0.1.0 🌈",
"prerelease": false,
"tag_name": "",
"tag_name": "v0.1.0",
"target_commitish": "refs/heads/master",
}
`)
Expand Down
11 changes: 4 additions & 7 deletions test/versions.test.js
@@ -1,4 +1,4 @@
const { getVersionInfo } = require('../lib/versions')
const { getVersionInfo, defaultVersionInfo } = require('../lib/versions')

describe('versions', () => {
it('extracts a version-like string from the last tag', () => {
Expand Down Expand Up @@ -170,13 +170,10 @@ describe('versions', () => {
expect(versionInfo.$NEXT_PATCH_VERSION_PATCH.template).toEqual('$PATCH')
})

it('returns undefined if no version was found in tag or name', () => {
const versionInfo = getVersionInfo({
tag_name: 'nope',
name: 'nope nope nope',
})
it('returns default version info if no version was found in tag or name', () => {
const versionInfo = getVersionInfo({})

expect(versionInfo).toEqual(undefined)
expect(versionInfo).toEqual(defaultVersionInfo)
})

it.each([
Expand Down