From a9c856c5a3f9bf54d677a9d6d9bc6f9aea083d12 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Feb 2022 08:19:58 +0100 Subject: [PATCH 1/3] Provide sane defaults if we have no prior releases Co-authored-by: Devon Stewart --- dist/index.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- lib/versions.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index ddddcea80..03c9b9489 100644 --- a/dist/index.js +++ b/dist/index.js @@ -129872,6 +129872,50 @@ const splitSemVersion = (input, versionKey = 'version') => { } } +const emptyVersionInfo = { + $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.0.1', + template: '$MAJOR.$MINOR.$PATCH', + inputVersion: null, + versionKeyIncrement: 'patch', + inc: 'patch', + $MAJOR: 0, + $MINOR: 0, + $PATCH: 1, + }, + $INPUT_VERSION: null, + $RESOLVED_VERSION: { + version: '0.0.0', + template: '$MAJOR.$MINOR.$PATCH', + inputVersion: null, + versionKeyIncrement: 'patch', + inc: 'patch', + $MAJOR: 0, + $MINOR: 0, + $PATCH: 0, + }, +} + const getTemplatableVersion = (input) => { const templatableVersion = { $NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }), @@ -129965,7 +130009,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return + return emptyVersionInfo } return { diff --git a/lib/versions.js b/lib/versions.js index d6daad6ee..bc5469786 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -19,6 +19,50 @@ const splitSemVersion = (input, versionKey = 'version') => { } } +const emptyVersionInfo = { + $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.0.1', + template: '$MAJOR.$MINOR.$PATCH', + inputVersion: null, + versionKeyIncrement: 'patch', + inc: 'patch', + $MAJOR: 0, + $MINOR: 0, + $PATCH: 1, + }, + $INPUT_VERSION: null, + $RESOLVED_VERSION: { + version: '0.0.0', + template: '$MAJOR.$MINOR.$PATCH', + inputVersion: null, + versionKeyIncrement: 'patch', + inc: 'patch', + $MAJOR: 0, + $MINOR: 0, + $PATCH: 0, + }, +} + const getTemplatableVersion = (input) => { const templatableVersion = { $NEXT_MAJOR_VERSION: splitSemVersion({ ...input, inc: 'major' }), @@ -112,7 +156,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return + return emptyVersionInfo } return { From 1631f7a81c97b0bf8eca45ece15bf8728f5ee09f Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Feb 2022 08:39:52 +0100 Subject: [PATCH 2/3] the sane default should start in a minor as 0.0.1 does not make sense from a semver prespective some tools cannot handle 0.0.1 as a starting point --- dist/index.js | 11 ++++++----- lib/versions.js | 11 ++++++----- test/index.test.js | 6 +++--- test/versions.test.js | 9 +++------ 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/dist/index.js b/dist/index.js index 03c9b9489..cb1b97e4d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -129894,24 +129894,24 @@ const emptyVersionInfo = { $PATCH: 0, }, $NEXT_PATCH_VERSION: { - version: '0.0.1', + version: '0.1.0', template: '$MAJOR.$MINOR.$PATCH', inputVersion: null, versionKeyIncrement: 'patch', inc: 'patch', $MAJOR: 0, - $MINOR: 0, - $PATCH: 1, + $MINOR: 1, + $PATCH: 0, }, $INPUT_VERSION: null, $RESOLVED_VERSION: { - version: '0.0.0', + version: '0.1.0', template: '$MAJOR.$MINOR.$PATCH', inputVersion: null, versionKeyIncrement: 'patch', inc: 'patch', $MAJOR: 0, - $MINOR: 0, + $MINOR: 1, $PATCH: 0, }, } @@ -130023,6 +130023,7 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo +exports.emptyVersionInfo = emptyVersionInfo /***/ }), diff --git a/lib/versions.js b/lib/versions.js index bc5469786..bc4048a25 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -41,24 +41,24 @@ const emptyVersionInfo = { $PATCH: 0, }, $NEXT_PATCH_VERSION: { - version: '0.0.1', + version: '0.1.0', template: '$MAJOR.$MINOR.$PATCH', inputVersion: null, versionKeyIncrement: 'patch', inc: 'patch', $MAJOR: 0, - $MINOR: 0, - $PATCH: 1, + $MINOR: 1, + $PATCH: 0, }, $INPUT_VERSION: null, $RESOLVED_VERSION: { - version: '0.0.0', + version: '0.1.0', template: '$MAJOR.$MINOR.$PATCH', inputVersion: null, versionKeyIncrement: 'patch', inc: 'patch', $MAJOR: 0, - $MINOR: 0, + $MINOR: 1, $PATCH: 0, }, } @@ -170,3 +170,4 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo +exports.emptyVersionInfo = emptyVersionInfo diff --git a/test/index.test.js b/test/index.test.js index 4a43c3243..3f2671444 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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') @@ -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", } `) diff --git a/test/versions.test.js b/test/versions.test.js index e8fa6fea1..97cee5027 100644 --- a/test/versions.test.js +++ b/test/versions.test.js @@ -1,4 +1,4 @@ -const { getVersionInfo } = require('../lib/versions') +const { getVersionInfo, emptyVersionInfo } = require('../lib/versions') describe('versions', () => { it('extracts a version-like string from the last tag', () => { @@ -171,12 +171,9 @@ describe('versions', () => { }) it('returns undefined if no version was found in tag or name', () => { - const versionInfo = getVersionInfo({ - tag_name: 'nope', - name: 'nope nope nope', - }) + const versionInfo = getVersionInfo({}) - expect(versionInfo).toEqual(undefined) + expect(versionInfo).toEqual(emptyVersionInfo) }) it.each([ From 4a66b87ffb6c96eee19cb48b10b16bb9909839b8 Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Sun, 13 Feb 2022 08:45:34 +0100 Subject: [PATCH 3/3] fix test and variable name --- dist/index.js | 6 +++--- lib/versions.js | 6 +++--- test/versions.test.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index cb1b97e4d..b537eab14 100644 --- a/dist/index.js +++ b/dist/index.js @@ -129872,7 +129872,7 @@ const splitSemVersion = (input, versionKey = 'version') => { } } -const emptyVersionInfo = { +const defaultVersionInfo = { $NEXT_MAJOR_VERSION: { version: '1.0.0', template: '$MAJOR.$MINOR.$PATCH', @@ -130009,7 +130009,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return emptyVersionInfo + return defaultVersionInfo } return { @@ -130023,7 +130023,7 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo -exports.emptyVersionInfo = emptyVersionInfo +exports.defaultVersionInfo = defaultVersionInfo /***/ }), diff --git a/lib/versions.js b/lib/versions.js index bc4048a25..abff55e1b 100644 --- a/lib/versions.js +++ b/lib/versions.js @@ -19,7 +19,7 @@ const splitSemVersion = (input, versionKey = 'version') => { } } -const emptyVersionInfo = { +const defaultVersionInfo = { $NEXT_MAJOR_VERSION: { version: '1.0.0', template: '$MAJOR.$MINOR.$PATCH', @@ -156,7 +156,7 @@ const getVersionInfo = ( inputVersion = coerceVersion(inputVersion) if (!version && !inputVersion) { - return emptyVersionInfo + return defaultVersionInfo } return { @@ -170,4 +170,4 @@ const getVersionInfo = ( } exports.getVersionInfo = getVersionInfo -exports.emptyVersionInfo = emptyVersionInfo +exports.defaultVersionInfo = defaultVersionInfo diff --git a/test/versions.test.js b/test/versions.test.js index 97cee5027..4cb929bda 100644 --- a/test/versions.test.js +++ b/test/versions.test.js @@ -1,4 +1,4 @@ -const { getVersionInfo, emptyVersionInfo } = require('../lib/versions') +const { getVersionInfo, defaultVersionInfo } = require('../lib/versions') describe('versions', () => { it('extracts a version-like string from the last tag', () => { @@ -170,10 +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', () => { + it('returns default version info if no version was found in tag or name', () => { const versionInfo = getVersionInfo({}) - expect(versionInfo).toEqual(emptyVersionInfo) + expect(versionInfo).toEqual(defaultVersionInfo) }) it.each([