Skip to content

Commit

Permalink
fix(version): --changelog-include-commits-[x] in cli should be truthy
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Aug 29, 2022
1 parent e05fc9e commit 1ddde05
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
8 changes: 7 additions & 1 deletion .vscode/launch.json
Expand Up @@ -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",
Expand Down
Expand Up @@ -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',
}),
Expand Down Expand Up @@ -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',
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/conventional-commits/update-changelog.ts
Expand Up @@ -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);
}
Expand Down
Expand Up @@ -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 =
Expand All @@ -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}}' || '')
Expand Down
4 changes: 3 additions & 1 deletion packages/version/src/__tests__/version-command.spec.ts
Expand Up @@ -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',
Expand All @@ -366,7 +366,9 @@ describe('VersionCommand', () => {
'github'
)
);
await command;

expect(command.changelogIncludeCommitsClientLogin).toBe(true);
expect(getCommitsSinceLastRelease).toHaveBeenCalled();
});
});
Expand Down
23 changes: 14 additions & 9 deletions packages/version/src/version-command.ts
Expand Up @@ -60,6 +60,8 @@ export class VersionCommand extends Command<VersionCommandOption> {
name = 'version' as CommandType;

globalVersion = '';
changelogIncludeCommitsClientLogin?: boolean | string;
changelogIncludeCommitsGitAuthor?: boolean | string;
commitsSinceLastRelease?: RemoteCommit[];
packagesToVersion: Package[] = [];
updatesVersions?: Map<string, string>;
Expand Down Expand Up @@ -104,6 +106,8 @@ export class VersionCommand extends Command<VersionCommandOption> {
// override durable options provided by a config file
const {
amend,
changelogIncludeCommitsClientLogin,
changelogIncludeCommitsGitAuthor,
commitHooks = true,
gitRemote = 'origin',
gitTagVersion = true,
Expand All @@ -120,6 +124,10 @@ export class VersionCommand extends Command<VersionCommandOption> {
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
Expand Down Expand Up @@ -249,7 +257,7 @@ export class VersionCommand extends Command<VersionCommandOption> {
);
}

if (this.options.changelogIncludeCommitsClientLogin && this.options.changelogIncludeCommitsGitAuthor) {
if (this.changelogIncludeCommitsClientLogin && this.changelogIncludeCommitsGitAuthor) {
throw new ValidationError(
'ENOTALLOWED',
dedent`
Expand All @@ -267,8 +275,7 @@ export class VersionCommand extends Command<VersionCommandOption> {

// 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',
Expand Down Expand Up @@ -580,8 +587,6 @@ export class VersionCommand extends Command<VersionCommandOption> {
const {
conventionalCommits,
changelogPreset,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
changelog = true,
Expand Down Expand Up @@ -651,8 +656,8 @@ export class VersionCommand extends Command<VersionCommandOption> {
changelogPreset,
rootPath,
tagPrefix: this.tagPrefix,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogIncludeCommitsGitAuthor: this.changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin: this.changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
commitsSinceLastRelease: this.commitsSinceLastRelease,
Expand Down Expand Up @@ -735,8 +740,8 @@ export class VersionCommand extends Command<VersionCommandOption> {
rootPath,
tagPrefix: this.tagPrefix,
version: this.globalVersion,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogIncludeCommitsGitAuthor: this.changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin: this.changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
commitsSinceLastRelease: this.commitsSinceLastRelease,
Expand Down

0 comments on commit 1ddde05

Please sign in to comment.