From 1ddde050ccfb285725efb84869adfba733a4dc0c Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Mon, 29 Aug 2022 18:29:29 -0400 Subject: [PATCH] fix(version): --changelog-include-commits-[x] in cli should be truthy --- .vscode/launch.json | 8 ++++++- .../__tests__/conventional-commits.spec.ts | 4 ++-- .../conventional-commits/update-changelog.ts | 7 ++++-- .../writer-opts-transform.ts | 4 ++-- .../src/__tests__/version-command.spec.ts | 4 +++- packages/version/src/version-command.ts | 23 +++++++++++-------- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index b23f86fa..9696ad71 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -23,7 +23,13 @@ "request": "launch", "runtimeExecutable": "node", "runtimeArgs": ["--nolazy", "-r", "tsm"], - "args": ["packages/cli/src/cli.ts", "version", "--git-dry-run"], + "args": [ + "packages/cli/src/cli.ts", + "version", + "--git-dry-run", + "--changelog-include-commits-client-login", + "--conventional-commits" + ], "cwd": "${workspaceRoot}", "console": "integratedTerminal", "internalConsoleOptions": "openOnSessionStart", diff --git a/packages/core/src/conventional-commits/__tests__/conventional-commits.spec.ts b/packages/core/src/conventional-commits/__tests__/conventional-commits.spec.ts index 9a22f0c4..923179f7 100644 --- a/packages/core/src/conventional-commits/__tests__/conventional-commits.spec.ts +++ b/packages/core/src/conventional-commits/__tests__/conventional-commits.spec.ts @@ -437,7 +437,7 @@ describe('conventional-commits', () => { tagPrefix: 'dragons-are-awesome', }), updateChangelog({ location: cwd } as Package, 'root', { - changelogIncludeCommitsGitAuthor: true, + changelogIncludeCommitsGitAuthor: '', // empty string would be treated the same as being true but without a format tagPrefix: 'dragons-are-awesome', version: '1.0.1', }), @@ -776,7 +776,7 @@ describe('conventional-commits', () => { const opt1s = { changelogPreset: 'conventional-changelog-angular', - changelogIncludeCommitsClientLogin: true, + changelogIncludeCommitsClientLogin: '', // empty string would be treated the same as being true but without a format commitsSinceLastRelease: [ { authorName: 'Tester McPerson', diff --git a/packages/core/src/conventional-commits/update-changelog.ts b/packages/core/src/conventional-commits/update-changelog.ts index 2f1e7e93..5632eeb6 100644 --- a/packages/core/src/conventional-commits/update-changelog.ts +++ b/packages/core/src/conventional-commits/update-changelog.ts @@ -51,9 +51,12 @@ export async function updateChangelog(pkg: Package, type: ChangelogType, updateO const gitRawCommitsOpts = Object.assign({}, options.config.gitRawCommitsOpts); // are we including commit author name/email or remote client login name - if (changelogIncludeCommitsGitAuthor) { + if (changelogIncludeCommitsGitAuthor || changelogIncludeCommitsGitAuthor === '') { setConfigChangelogCommitGitAuthor(config, gitRawCommitsOpts, writerOpts, changelogIncludeCommitsGitAuthor); - } else if (changelogIncludeCommitsClientLogin && commitsSinceLastRelease) { + } else if ( + (changelogIncludeCommitsClientLogin || changelogIncludeCommitsClientLogin === '') && + commitsSinceLastRelease + ) { // prettier-ignore setConfigChangelogCommitClientLogin(config, gitRawCommitsOpts, writerOpts, commitsSinceLastRelease, changelogIncludeCommitsClientLogin); } diff --git a/packages/core/src/conventional-commits/writer-opts-transform.ts b/packages/core/src/conventional-commits/writer-opts-transform.ts index 3872c768..7803504b 100644 --- a/packages/core/src/conventional-commits/writer-opts-transform.ts +++ b/packages/core/src/conventional-commits/writer-opts-transform.ts @@ -26,7 +26,7 @@ export function setConfigChangelogCommitGitAuthor( ) { gitRawCommitsOpts.format = GIT_COMMIT_WITH_AUTHOR_FORMAT; const extraCommitMsg = - typeof commitCustomFormat === 'string' + typeof commitCustomFormat === 'string' && commitCustomFormat !== '' ? commitCustomFormat.replace(/%a/g, '{{authorName}}' || '').replace(/%e/g, '{{authorEmail}}' || '') : `({{authorName}})`; writerOpts.commitPartial = @@ -53,7 +53,7 @@ export function setConfigChangelogCommitClientLogin( ) { gitRawCommitsOpts.format = GIT_COMMIT_WITH_AUTHOR_FORMAT; const extraCommitMsg = - typeof commitCustomFormat === 'string' + typeof commitCustomFormat === 'string' && commitCustomFormat !== '' ? commitCustomFormat .replace(/%a/g, '{{authorName}}' || '') .replace(/%e/g, '{{authorEmail}}' || '') diff --git a/packages/version/src/__tests__/version-command.spec.ts b/packages/version/src/__tests__/version-command.spec.ts index 5dde003f..dc880545 100644 --- a/packages/version/src/__tests__/version-command.spec.ts +++ b/packages/version/src/__tests__/version-command.spec.ts @@ -357,7 +357,7 @@ describe('VersionCommand', () => { it('call getCommitsSinceLastRelease() when --changelog-include-commits-client-login is provided', async () => { const testDir = await initFixture('normal'); - await new VersionCommand( + const command = new VersionCommand( createArgv( testDir, '--changelog-include-commits-client-login', @@ -366,7 +366,9 @@ describe('VersionCommand', () => { 'github' ) ); + await command; + expect(command.changelogIncludeCommitsClientLogin).toBe(true); expect(getCommitsSinceLastRelease).toHaveBeenCalled(); }); }); diff --git a/packages/version/src/version-command.ts b/packages/version/src/version-command.ts index 133e7584..4e840301 100644 --- a/packages/version/src/version-command.ts +++ b/packages/version/src/version-command.ts @@ -60,6 +60,8 @@ export class VersionCommand extends Command { name = 'version' as CommandType; globalVersion = ''; + changelogIncludeCommitsClientLogin?: boolean | string; + changelogIncludeCommitsGitAuthor?: boolean | string; commitsSinceLastRelease?: RemoteCommit[]; packagesToVersion: Package[] = []; updatesVersions?: Map; @@ -104,6 +106,8 @@ export class VersionCommand extends Command { // override durable options provided by a config file const { amend, + changelogIncludeCommitsClientLogin, + changelogIncludeCommitsGitAuthor, commitHooks = true, gitRemote = 'origin', gitTagVersion = true, @@ -120,6 +124,10 @@ export class VersionCommand extends Command { this.tagPrefix = tagVersionPrefix; this.commitAndTag = gitTagVersion; this.pushToRemote = gitTagVersion && amend !== true && push; + this.changelogIncludeCommitsClientLogin = + changelogIncludeCommitsClientLogin === '' ? true : changelogIncludeCommitsClientLogin; + this.changelogIncludeCommitsGitAuthor = + changelogIncludeCommitsGitAuthor === '' ? true : changelogIncludeCommitsGitAuthor; // never automatically push to remote when amending a commit // prettier-ignore @@ -249,7 +257,7 @@ export class VersionCommand extends Command { ); } - if (this.options.changelogIncludeCommitsClientLogin && this.options.changelogIncludeCommitsGitAuthor) { + if (this.changelogIncludeCommitsClientLogin && this.changelogIncludeCommitsGitAuthor) { throw new ValidationError( 'ENOTALLOWED', dedent` @@ -267,8 +275,7 @@ export class VersionCommand extends Command { // fetch all commits from remote server of the last release when user wants to include client login associated to each commits const remoteClient = this.options.createRelease || this.options.remoteClient; - const { conventionalCommits, changelogIncludeCommitsClientLogin } = this.options; - if (conventionalCommits && changelogIncludeCommitsClientLogin) { + if (this.options.conventionalCommits && this.changelogIncludeCommitsClientLogin) { if (!remoteClient) { throw new ValidationError( 'EMISSINGCLIENT', @@ -580,8 +587,6 @@ export class VersionCommand extends Command { const { conventionalCommits, changelogPreset, - changelogIncludeCommitsGitAuthor, - changelogIncludeCommitsClientLogin, changelogHeaderMessage, changelogVersionMessage, changelog = true, @@ -651,8 +656,8 @@ export class VersionCommand extends Command { changelogPreset, rootPath, tagPrefix: this.tagPrefix, - changelogIncludeCommitsGitAuthor, - changelogIncludeCommitsClientLogin, + changelogIncludeCommitsGitAuthor: this.changelogIncludeCommitsGitAuthor, + changelogIncludeCommitsClientLogin: this.changelogIncludeCommitsClientLogin, changelogHeaderMessage, changelogVersionMessage, commitsSinceLastRelease: this.commitsSinceLastRelease, @@ -735,8 +740,8 @@ export class VersionCommand extends Command { rootPath, tagPrefix: this.tagPrefix, version: this.globalVersion, - changelogIncludeCommitsGitAuthor, - changelogIncludeCommitsClientLogin, + changelogIncludeCommitsGitAuthor: this.changelogIncludeCommitsGitAuthor, + changelogIncludeCommitsClientLogin: this.changelogIncludeCommitsClientLogin, changelogHeaderMessage, changelogVersionMessage, commitsSinceLastRelease: this.commitsSinceLastRelease,