From 162b5665653ee8eda3d5cd5e5504b493f35568a1 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Thu, 5 Nov 2020 03:29:03 +0100 Subject: [PATCH 01/11] Add --release-draft-only --- readme.md | 27 ++++++++++--------- source/cli-implementation.js | 35 ++++++++++++++----------- source/git-util.js | 15 +++++++++++ source/index.js | 51 +++++++++++++++++++----------------- source/ui.js | 34 ++++++++++++++++++------ 5 files changed, 102 insertions(+), 60 deletions(-) diff --git a/readme.md b/readme.md index 034b4521..845306fb 100644 --- a/readme.md +++ b/readme.md @@ -50,19 +50,20 @@ $ np --help patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3 Options - --any-branch Allow publishing from any branch - --branch Name of the release branch (default: master) - --no-cleanup Skips cleanup of node_modules - --no-tests Skips tests - --yolo Skips cleanup and testing - --no-publish Skips publishing - --preview Show tasks without actually executing them - --tag Publish under a given dist-tag - --no-yarn Don't use Yarn - --contents Subdirectory to publish - --no-release-draft Skips opening a GitHub release draft - --test-script Name of npm run script to run tests before publishing (default: test) - --no-2fa Don't enable 2FA on new packages (not recommended) + --any-branch Allow publishing from any branch + --branch Name of the release branch (default: master) + --no-cleanup Skips cleanup of node_modules + --no-tests Skips tests + --yolo Skips cleanup and testing + --no-publish Skips publishing + --preview Show tasks without actually executing them + --tag Publish under a given dist-tag + --no-yarn Don't use Yarn + --contents Subdirectory to publish + --no-release-draft Skips opening a GitHub release draft + --release-draft-only Only opens a GitHub release draft for the latest published version + --test-script Name of npm run script to run tests before publishing (default: test) + --no-2fa Don't enable 2FA on new packages (not recommended) Examples $ np diff --git a/source/cli-implementation.js b/source/cli-implementation.js index eb9e0190..42d96210 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -21,19 +21,20 @@ const cli = meow(` ${version.SEMVER_INCREMENTS.join(' | ')} | 1.2.3 Options - --any-branch Allow publishing from any branch - --branch Name of the release branch (default: master) - --no-cleanup Skips cleanup of node_modules - --no-tests Skips tests - --yolo Skips cleanup and testing - --no-publish Skips publishing - --preview Show tasks without actually executing them - --tag Publish under a given dist-tag - --no-yarn Don't use Yarn - --contents Subdirectory to publish - --no-release-draft Skips opening a GitHub release draft - --test-script Name of npm run script to run tests before publishing (default: test) - --no-2fa Don't enable 2FA on new packages (not recommended) + --any-branch Allow publishing from any branch + --branch Name of the release branch (default: master) + --no-cleanup Skips cleanup of node_modules + --no-tests Skips tests + --yolo Skips cleanup and testing + --no-publish Skips publishing + --preview Show tasks without actually executing them + --tag Publish under a given dist-tag + --no-yarn Don't use Yarn + --contents Subdirectory to publish + --no-release-draft Skips opening a GitHub release draft + --release-draft-only Only opens a GitHub release draft for the latest published version + --test-script Name of npm run script to run tests before publishing (default: test) + --no-2fa Don't enable 2FA on new packages (not recommended) Examples $ np @@ -65,6 +66,9 @@ const cli = meow(` releaseDraft: { type: 'boolean' }, + releaseDraftOnly: { + type: 'boolean' + }, tag: { type: 'string' }, @@ -113,14 +117,15 @@ updateNotifier({pkg: cli.pkg}).notify(); flags['2fa'] = flags['2Fa']; } - const runPublish = flags.publish && !pkg.private; + const runPublish = !flags.releaseDraftOnly && flags.publish && !pkg.private; const availability = flags.publish ? await isPackageNameAvailable(pkg) : { isAvailable: false, isUnknown: false }; - const version = cli.input.length > 0 ? cli.input[0] : false; + // Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument. + const version = flags.releaseDraftOnly ? pkg.version : cli.input.length > 0 ? cli.input[0] : false; const options = await ui({ ...flags, diff --git a/source/git-util.js b/source/git-util.js index e3bd672d..6fcf5175 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -29,6 +29,21 @@ const firstCommit = async () => { return stdout; }; +exports.tagBeforeCurrentOrFirstCommit = async () => { + const {stdout} = await execa('git', ['tag']); + const tags = stdout.split('\n'); + + if (tags.length === 0) { + return null; + } + + if (tags.length === 1) { + return firstCommit(); + } + + return tags[tags.length - 2]; +} + exports.latestTagOrFirstCommit = async () => { let latest; try { diff --git a/source/index.js b/source/index.js index bc629844..1ecfc0fc 100644 --- a/source/index.js +++ b/source/index.js @@ -48,8 +48,8 @@ module.exports = async (input = 'patch', options) => { } const pkg = util.readPkg(options.contents); - const runTests = options.tests && !options.yolo; - const runCleanup = options.cleanup && !options.yolo; + const runTests = options.tests && !options.yolo && !options.releaseDraftOnly; + const runCleanup = options.cleanup && !options.yolo && !options.releaseDraftOnly; const pkgManager = options.yarn === true ? 'yarn' : 'npm'; const pkgManagerName = options.yarn === true ? 'Yarn' : 'npm'; const rootDir = pkgDir.sync(); @@ -107,6 +107,7 @@ module.exports = async (input = 'patch', options) => { }, { title: 'Git', + enabled: () => !options.releaseDraftOnly, task: () => gitTasks(options) } ], { @@ -167,28 +168,30 @@ module.exports = async (input = 'patch', options) => { ]); } - tasks.add([ - { - title: 'Bumping version using Yarn', - enabled: () => options.yarn === true, - skip: () => { - if (options.preview) { - return `[Preview] Command not executed: yarn version --new-version ${input}.`; - } - }, - task: () => exec('yarn', ['version', '--new-version', input]) - }, - { - title: 'Bumping version using npm', - enabled: () => options.yarn === false, - skip: () => { - if (options.preview) { - return `[Preview] Command not executed: npm version ${input}.`; - } + if (!options.releaseDraftOnly) { + tasks.add([ + { + title: 'Bumping version using Yarn', + enabled: () => options.yarn === true, + skip: () => { + if (options.preview) { + return `[Preview] Command not executed: yarn version --new-version ${input}.`; + } + }, + task: () => exec('yarn', ['version', '--new-version', input]) }, - task: () => exec('npm', ['version', input]) - } - ]); + { + title: 'Bumping version using npm', + enabled: () => options.yarn === false, + skip: () => { + if (options.preview) { + return `[Preview] Command not executed: npm version ${input}.`; + } + }, + task: () => exec('npm', ['version', input]) + } + ]); + } if (options.runPublish) { tasks.add([ @@ -257,7 +260,7 @@ module.exports = async (input = 'patch', options) => { } }); - if (options.releaseDraft) { + if (options.releaseDraft || options.releaseDraftOnly) { tasks.add({ title: 'Creating release draft on GitHub', enabled: () => isOnGitHub === true, diff --git a/source/ui.js b/source/ui.js index 7c5f6ad8..c76e5776 100644 --- a/source/ui.js +++ b/source/ui.js @@ -11,9 +11,14 @@ const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl, isExternalRegistry} const version = require('./version'); const prettyVersionDiff = require('./pretty-version-diff'); -const printCommitLog = async (repoUrl, registryUrl) => { - const latest = await git.latestTagOrFirstCommit(); - const log = await git.commitLogFromRevision(latest); +const printCommitLog = async (repoUrl, registryUrl, latestTag) => { + const revision = latestTag ? await git.latestTagOrFirstCommit() : await git.tagBeforeCurrentOrFirstCommit(); + if (revision === null) { + console.error(`The package hasn't been published yet.`); + process.exit(1); + } + + const log = await git.commitLogFromRevision(revision); if (!log) { return { @@ -22,7 +27,7 @@ const printCommitLog = async (repoUrl, registryUrl) => { }; } - const commits = log.split('\n') + let commits = log.split('\n') .map(commit => { const splitIndex = commit.lastIndexOf(' '); return { @@ -31,6 +36,14 @@ const printCommitLog = async (repoUrl, registryUrl) => { }; }); + if (!latestTag) { + // Remove the version bump commit from the commit list. + const latestTag = await git.latestTag(); + if (latestTag.match(commits[0].message)) { + commits = commits.slice(1); + } + } + const history = commits.map(commit => { const commitMessage = util.linkifyIssues(repoUrl, commit.message); const commitId = util.linkifyCommit(repoUrl, commit.id); @@ -39,9 +52,9 @@ const printCommitLog = async (repoUrl, registryUrl) => { const releaseNotes = nextTag => commits.map(commit => `- ${htmlEscape(commit.message)} ${commit.id}` - ).join('\n') + `\n\n${repoUrl}/compare/${latest}...${nextTag}`; + ).join('\n') + `\n\n${repoUrl}/compare/${revision}...${nextTag}`; - const commitRange = util.linkifyCommitRange(repoUrl, `${latest}...master`); + const commitRange = util.linkifyCommitRange(repoUrl, `${revision}...master`); console.log(`${chalk.bold('Commits:')}\n${history}\n\n${chalk.bold('Commit Range:')}\n${commitRange}\n\n${chalk.bold('Registry:')}\n${registryUrl}\n`); @@ -92,7 +105,11 @@ module.exports = async (options, pkg) => { } } - console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(current: ${oldVersion})`)}\n`); + if (options.releaseDraftOnly) { + console.log(`\nCreate a release draft on GitHub for ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(current: ${oldVersion})`)}\n`); + } else { + console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(current: ${oldVersion})`)}\n`); + } const prompts = [ { @@ -176,7 +193,8 @@ module.exports = async (options, pkg) => { } ]; - const {hasCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl); + const useLatestTag = !options.releaseDraftOnly; + const {hasCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl, useLatestTag); if (options.version) { return { From 98de74e3b1555d29e8de47a7cc9006ae11d8b6ac Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Thu, 5 Nov 2020 04:57:18 +0100 Subject: [PATCH 02/11] Fix linting --- source/cli-implementation.js | 2 +- source/git-util.js | 2 +- source/ui.js | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index 42d96210..aaad0fd5 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -125,7 +125,7 @@ updateNotifier({pkg: cli.pkg}).notify(); }; // Use current (latest) version when 'releaseDraftOnly', otherwise use the first argument. - const version = flags.releaseDraftOnly ? pkg.version : cli.input.length > 0 ? cli.input[0] : false; + const version = flags.releaseDraftOnly ? pkg.version : (cli.input.length > 0 ? cli.input[0] : false); const options = await ui({ ...flags, diff --git a/source/git-util.js b/source/git-util.js index 6fcf5175..e4687ded 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -42,7 +42,7 @@ exports.tagBeforeCurrentOrFirstCommit = async () => { } return tags[tags.length - 2]; -} +}; exports.latestTagOrFirstCommit = async () => { let latest; diff --git a/source/ui.js b/source/ui.js index c76e5776..b7ed592c 100644 --- a/source/ui.js +++ b/source/ui.js @@ -14,8 +14,7 @@ const prettyVersionDiff = require('./pretty-version-diff'); const printCommitLog = async (repoUrl, registryUrl, latestTag) => { const revision = latestTag ? await git.latestTagOrFirstCommit() : await git.tagBeforeCurrentOrFirstCommit(); if (revision === null) { - console.error(`The package hasn't been published yet.`); - process.exit(1); + throw new Error('The package hasn\'t been published yet.'); } const log = await git.commitLogFromRevision(revision); From 1ebc7a65d3e016a4ac7aa0d98bcbc4ebb4d3ba98 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Sat, 28 Nov 2020 22:27:22 +0100 Subject: [PATCH 03/11] Remove null usage --- source/git-util.js | 2 +- source/ui.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/git-util.js b/source/git-util.js index e4687ded..4209501c 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -34,7 +34,7 @@ exports.tagBeforeCurrentOrFirstCommit = async () => { const tags = stdout.split('\n'); if (tags.length === 0) { - return null; + return; } if (tags.length === 1) { diff --git a/source/ui.js b/source/ui.js index b7ed592c..4af0adba 100644 --- a/source/ui.js +++ b/source/ui.js @@ -13,7 +13,7 @@ const prettyVersionDiff = require('./pretty-version-diff'); const printCommitLog = async (repoUrl, registryUrl, latestTag) => { const revision = latestTag ? await git.latestTagOrFirstCommit() : await git.tagBeforeCurrentOrFirstCommit(); - if (revision === null) { + if (!revision) { throw new Error('The package hasn\'t been published yet.'); } From 516c89ece474e7f3729b97c175aeeeaf23aabd5c Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Sat, 28 Nov 2020 22:50:10 +0100 Subject: [PATCH 04/11] Remove most conditionals --- source/index.js | 56 +++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/source/index.js b/source/index.js index 1ecfc0fc..5aaca744 100644 --- a/source/index.js +++ b/source/index.js @@ -48,8 +48,8 @@ module.exports = async (input = 'patch', options) => { } const pkg = util.readPkg(options.contents); - const runTests = options.tests && !options.yolo && !options.releaseDraftOnly; - const runCleanup = options.cleanup && !options.yolo && !options.releaseDraftOnly; + const runTests = options.tests && !options.yolo; + const runCleanup = options.cleanup && !options.yolo; const pkgManager = options.yarn === true ? 'yarn' : 'npm'; const pkgManagerName = options.yarn === true ? 'Yarn' : 'npm'; const rootDir = pkgDir.sync(); @@ -58,6 +58,11 @@ module.exports = async (input = 'patch', options) => { const testScript = options.testScript || 'test'; const testCommand = options.testScript ? ['run', testScript] : [testScript]; + if (options.releaseDraftOnly) { + await releaseTaskHelper(options, pkg); + return pkg; + } + let publishStatus = 'UNKNOWN'; let pushedObjects; @@ -107,7 +112,6 @@ module.exports = async (input = 'patch', options) => { }, { title: 'Git', - enabled: () => !options.releaseDraftOnly, task: () => gitTasks(options) } ], { @@ -168,30 +172,28 @@ module.exports = async (input = 'patch', options) => { ]); } - if (!options.releaseDraftOnly) { - tasks.add([ - { - title: 'Bumping version using Yarn', - enabled: () => options.yarn === true, - skip: () => { - if (options.preview) { - return `[Preview] Command not executed: yarn version --new-version ${input}.`; - } - }, - task: () => exec('yarn', ['version', '--new-version', input]) + tasks.add([ + { + title: 'Bumping version using Yarn', + enabled: () => options.yarn === true, + skip: () => { + if (options.preview) { + return `[Preview] Command not executed: yarn version --new-version ${input}.`; + } }, - { - title: 'Bumping version using npm', - enabled: () => options.yarn === false, - skip: () => { - if (options.preview) { - return `[Preview] Command not executed: npm version ${input}.`; - } - }, - task: () => exec('npm', ['version', input]) - } - ]); - } + task: () => exec('yarn', ['version', '--new-version', input]) + }, + { + title: 'Bumping version using npm', + enabled: () => options.yarn === false, + skip: () => { + if (options.preview) { + return `[Preview] Command not executed: npm version ${input}.`; + } + }, + task: () => exec('npm', ['version', input]) + } + ]); if (options.runPublish) { tasks.add([ @@ -260,7 +262,7 @@ module.exports = async (input = 'patch', options) => { } }); - if (options.releaseDraft || options.releaseDraftOnly) { + if (options.releaseDraft) { tasks.add({ title: 'Creating release draft on GitHub', enabled: () => isOnGitHub === true, From 1e61beec3f922675fc861e58af9d87d30995c778 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Mon, 21 Dec 2020 12:02:35 +0100 Subject: [PATCH 05/11] Fix readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 845306fb..0fd86cb6 100644 --- a/readme.md +++ b/readme.md @@ -61,7 +61,7 @@ $ np --help --no-yarn Don't use Yarn --contents Subdirectory to publish --no-release-draft Skips opening a GitHub release draft - --release-draft-only Only opens a GitHub release draft for the latest published version + --release-draft-only Only opens a GitHub release draft --test-script Name of npm run script to run tests before publishing (default: test) --no-2fa Don't enable 2FA on new packages (not recommended) From 3753c2dedc9ce14a71b69f992f03c9eecbd2bf30 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Mon, 21 Dec 2020 14:00:47 +0100 Subject: [PATCH 06/11] Suppress publish message --- source/cli-implementation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/cli-implementation.js b/source/cli-implementation.js index aaad0fd5..f5ded4b1 100755 --- a/source/cli-implementation.js +++ b/source/cli-implementation.js @@ -141,7 +141,7 @@ updateNotifier({pkg: cli.pkg}).notify(); console.log(); // Prints a newline for readability const newPkg = await np(options.version, options); - if (options.preview) { + if (options.preview || options.releaseDraftOnly) { return; } From d913b74c3102f2141ae1e2a9e04066502fc6fe09 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Mon, 21 Dec 2020 14:04:18 +0100 Subject: [PATCH 07/11] Ignore unreleased commits --- source/git-util.js | 2 +- source/ui.js | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/source/git-util.js b/source/git-util.js index 4209501c..50d639cc 100644 --- a/source/git-util.js +++ b/source/git-util.js @@ -29,7 +29,7 @@ const firstCommit = async () => { return stdout; }; -exports.tagBeforeCurrentOrFirstCommit = async () => { +exports.previousTagOrFirstCommit = async () => { const {stdout} = await execa('git', ['tag']); const tags = stdout.split('\n'); diff --git a/source/ui.js b/source/ui.js index 4af0adba..88c8e910 100644 --- a/source/ui.js +++ b/source/ui.js @@ -11,8 +11,8 @@ const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl, isExternalRegistry} const version = require('./version'); const prettyVersionDiff = require('./pretty-version-diff'); -const printCommitLog = async (repoUrl, registryUrl, latestTag) => { - const revision = latestTag ? await git.latestTagOrFirstCommit() : await git.tagBeforeCurrentOrFirstCommit(); +const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { + const revision = fromLatestTag ? await git.latestTagOrFirstCommit() : await git.previousTagOrFirstCommit(); if (!revision) { throw new Error('The package hasn\'t been published yet.'); } @@ -35,12 +35,13 @@ const printCommitLog = async (repoUrl, registryUrl, latestTag) => { }; }); - if (!latestTag) { - // Remove the version bump commit from the commit list. + if (!fromLatestTag) { const latestTag = await git.latestTag(); - if (latestTag.match(commits[0].message)) { - commits = commits.slice(1); - } + const versionBumpCommitName = latestTag.slice(1); // Name v1.0.1 becomes 1.0.1 + const versionBumpCommitIndex = commits.findIndex(commit => commit.message === versionBumpCommitName); + + // Get rid of unreleased commits and of the version bump commit. + commits = commits.slice(versionBumpCommitIndex + 1); } const history = commits.map(commit => { From 1680ce013810a21dd7ad0522f53f8c79a23d802a Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Mon, 21 Dec 2020 14:17:38 +0100 Subject: [PATCH 08/11] Add warning on unreleased commits --- source/ui.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/source/ui.js b/source/ui.js index 88c8e910..abe0c3de 100644 --- a/source/ui.js +++ b/source/ui.js @@ -196,6 +196,22 @@ module.exports = async (options, pkg) => { const useLatestTag = !options.releaseDraftOnly; const {hasCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl, useLatestTag); + if (hasCommits && options.releaseDraftOnly) { + const answers = await inquirer.prompt([{ + type: 'confirm', + name: 'confirm', + message: 'Unreleased commits found. They won\'t be included in the release draft, continue?', + default: false + }]); + + if (!answers.confirm) { + return { + ...options, + ...answers + }; + } + } + if (options.version) { return { ...options, From 4b6c2470920133a25421f9190f929e235f560af7 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Mon, 21 Dec 2020 14:42:13 +0100 Subject: [PATCH 09/11] Fix commit range --- source/ui.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/ui.js b/source/ui.js index abe0c3de..4b6d9958 100644 --- a/source/ui.js +++ b/source/ui.js @@ -26,6 +26,8 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { }; } + let commitRangeText = `${revision}...master`; + let commits = log.split('\n') .map(commit => { const splitIndex = commit.lastIndexOf(' '); @@ -37,6 +39,8 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { if (!fromLatestTag) { const latestTag = await git.latestTag(); + commitRangeText = `${revision}...${latestTag}`; + const versionBumpCommitName = latestTag.slice(1); // Name v1.0.1 becomes 1.0.1 const versionBumpCommitIndex = commits.findIndex(commit => commit.message === versionBumpCommitName); @@ -54,7 +58,7 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { `- ${htmlEscape(commit.message)} ${commit.id}` ).join('\n') + `\n\n${repoUrl}/compare/${revision}...${nextTag}`; - const commitRange = util.linkifyCommitRange(repoUrl, `${revision}...master`); + const commitRange = util.linkifyCommitRange(repoUrl, commitRangeText); console.log(`${chalk.bold('Commits:')}\n${history}\n\n${chalk.bold('Commit Range:')}\n${commitRange}\n\n${chalk.bold('Registry:')}\n${registryUrl}\n`); From 4c1b8efedbc26bc82350ce460092cdb32f8f8b74 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Thu, 24 Dec 2020 11:31:42 +0100 Subject: [PATCH 10/11] Fix spelling --- source/ui.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/ui.js b/source/ui.js index 4b6d9958..f3b52455 100644 --- a/source/ui.js +++ b/source/ui.js @@ -14,7 +14,7 @@ const prettyVersionDiff = require('./pretty-version-diff'); const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { const revision = fromLatestTag ? await git.latestTagOrFirstCommit() : await git.previousTagOrFirstCommit(); if (!revision) { - throw new Error('The package hasn\'t been published yet.'); + throw new Error('The package has not been published yet.'); } const log = await git.commitLogFromRevision(revision); @@ -204,7 +204,7 @@ module.exports = async (options, pkg) => { const answers = await inquirer.prompt([{ type: 'confirm', name: 'confirm', - message: 'Unreleased commits found. They won\'t be included in the release draft, continue?', + message: 'Unreleased commits found. They won\'t be included in the release draft. Continue?', default: false }]); From 063eec160b3c76c6fe9f1208efd405472c82e068 Mon Sep 17 00:00:00 2001 From: Corentin Girard Date: Thu, 24 Dec 2020 12:26:03 +0100 Subject: [PATCH 11/11] Fix behavior when no unreleased commit --- source/ui.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/ui.js b/source/ui.js index f3b52455..b9e6333e 100644 --- a/source/ui.js +++ b/source/ui.js @@ -22,10 +22,12 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { if (!log) { return { hasCommits: false, + hasUnreleasedCommits: false, releaseNotes: () => {} }; } + let hasUnreleasedCommits = false; let commitRangeText = `${revision}...master`; let commits = log.split('\n') @@ -39,11 +41,14 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { if (!fromLatestTag) { const latestTag = await git.latestTag(); - commitRangeText = `${revision}...${latestTag}`; - const versionBumpCommitName = latestTag.slice(1); // Name v1.0.1 becomes 1.0.1 const versionBumpCommitIndex = commits.findIndex(commit => commit.message === versionBumpCommitName); + if (versionBumpCommitIndex > 0) { + commitRangeText = `${revision}...${latestTag}`; + hasUnreleasedCommits = true; + } + // Get rid of unreleased commits and of the version bump commit. commits = commits.slice(versionBumpCommitIndex + 1); } @@ -64,6 +69,7 @@ const printCommitLog = async (repoUrl, registryUrl, fromLatestTag) => { return { hasCommits: true, + hasUnreleasedCommits, releaseNotes }; }; @@ -198,9 +204,9 @@ module.exports = async (options, pkg) => { ]; const useLatestTag = !options.releaseDraftOnly; - const {hasCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl, useLatestTag); + const {hasCommits, hasUnreleasedCommits, releaseNotes} = await printCommitLog(repoUrl, registryUrl, useLatestTag); - if (hasCommits && options.releaseDraftOnly) { + if (hasUnreleasedCommits && options.releaseDraftOnly) { const answers = await inquirer.prompt([{ type: 'confirm', name: 'confirm',