Skip to content

Commit

Permalink
fix(version): rename option to --changelog-include-commits-git-author
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Jul 28, 2022
1 parent ed5841d commit b095637
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 24 deletions.
8 changes: 8 additions & 0 deletions packages/cli/src/cli-commands/cli-version-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ export default {
requiresArg: true,
type: 'string',
},
// @deprecated - Option RENAMED
'changelog-include-commit-author-fullname': {
describe:
"Specify if we want to include the commit author's name, this option is only available when using --conventional-commits with changelogs. We can also optionally provide a custom message or else a default format will be used.",
group: 'Version Command Options:',
requiresArg: false,
type: 'string',
},
'changelog-include-commits-git-author': {
describe:
"Specify if we want to include the commit git author's name, this option is only available when using --conventional-commits with changelogs. We can also optionally provide a custom message or else a default format will be used.",
group: 'Version Command Options:',
requiresArg: false,
type: 'string',
},
'changelog-include-commits-client-login': {
describe:
'Specify if we want to include the commit remote client login name (ie GitHub username), this option is only available when using --conventional-commits with changelogs. We can also optionally provide a custom message or else a default format will be used.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ describe('conventional-commits', () => {
`);
});

it('supports custom tagPrefix in fixed mode when --changelog-include-commit-author-fullname is provided', async () => {
it('supports custom tagPrefix in fixed mode when --changelog-include-commits-git-author is provided', async () => {
const cwd = await initFixture('fixed');

await gitTag(cwd, 'dragons-are-awesome1.0.0');
Expand All @@ -432,11 +432,11 @@ describe('conventional-commits', () => {

const [leafChangelog, rootChangelog] = await Promise.all([
updateChangelog(pkg1, 'fixed', {
changelogIncludeCommitAuthorFullname: true,
changelogIncludeCommitsGitAuthor: true,
tagPrefix: 'dragons-are-awesome',
}),
updateChangelog({ location: cwd } as Package, 'root', {
changelogIncludeCommitAuthorFullname: true,
changelogIncludeCommitsGitAuthor: true,
tagPrefix: 'dragons-are-awesome',
version: '1.0.1',
}),
Expand Down Expand Up @@ -469,7 +469,7 @@ describe('conventional-commits', () => {
await gitCommit(cwd, 'fix: A third commit for our CHANGELOG');

const lastRootChangelog = await updateChangelog({ location: cwd } as Package, 'root', {
changelogIncludeCommitAuthorFullname: true,
changelogIncludeCommitsGitAuthor: true,
tagPrefix: 'dragons-are-awesome',
version: '1.0.2',
});
Expand Down Expand Up @@ -677,7 +677,7 @@ describe('conventional-commits', () => {

const opts = {
changelogPreset: 'conventional-changelog-angular',
changelogIncludeCommitAuthorFullname: true,
changelogIncludeCommitsGitAuthor: true,
};
const [changelogOne, changelogTwo] = await Promise.all([
updateChangelog(pkg1, 'independent', opts),
Expand All @@ -702,7 +702,7 @@ describe('conventional-commits', () => {
`);
});

it('updates independent changelogs when providing --changelog-include-commit-author-fullname with a custom format when defined', async () => {
it('updates independent changelogs when providing --changelog-include-commits-git-author with a custom format when defined', async () => {
const cwd = await initFixture('independent');

await gitTag(cwd, '[email protected]');
Expand All @@ -726,7 +726,7 @@ describe('conventional-commits', () => {

const opts = {
changelogPreset: 'conventional-changelog-angular',
changelogIncludeCommitAuthorFullname: ' by (**%a**)',
changelogIncludeCommitsGitAuthor: ' by (**%a**)',
};
const [changelogOne, changelogTwo] = await Promise.all([
updateChangelog(pkg1, 'independent', opts),
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/conventional-commits/update-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function updateChangelog(pkg: Package, type: ChangelogType, updateO

const {
changelogPreset,
changelogIncludeCommitAuthorFullname,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogHeaderMessage = '',
changelogVersionMessage = '',
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function updateChangelog(pkg: Package, type: ChangelogType, updateO
// we will later extract a defined token from the string, of ">>author=%an<<",
// and reformat the string to get a commit string that would add (@authorName) to the end of the commit string, ie:
// **deps:** update all non-major dependencies ([ed1db35](https://github.com/.../ed1db35)) (@Renovate-Bot)
if (changelogIncludeCommitAuthorFullname) {
if (changelogIncludeCommitsGitAuthor) {
gitRawCommitsOpts.format = '%B%n-hash-%n%H>>author=%an<<';
}

Expand Down Expand Up @@ -92,8 +92,8 @@ export async function updateChangelog(pkg: Package, type: ChangelogType, updateO
let newEntry = inputEntry;

// include commit author name or commit client login name
if (changelogIncludeCommitAuthorFullname) {
newEntry = parseChangelogCommitAuthorFullName(inputEntry, changelogIncludeCommitAuthorFullname);
if (changelogIncludeCommitsGitAuthor) {
newEntry = parseChangelogCommitAuthorFullName(inputEntry, changelogIncludeCommitsGitAuthor);
} else if (changelogIncludeCommitsClientLogin && commitsSinceLastRelease) {
newEntry = parseChangelogCommitClientLogin(
inputEntry,
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/models/command-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ export interface VersionCommandOption {
* Specify if we want to include the commit author's name, this option is only available when using --conventional-commits with changelogs.
* We can also optionally provide a custom message or else a default format will be used.
*/
changelogIncludeCommitsGitAuthor?: boolean | string;

/** @deprecated option renamed to `changelogIncludeCommitsGitAuthor` */
changelogIncludeCommitAuthorFullname?: boolean | string;

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ export interface UpdateChangelogOption {
changelogHeaderMessage?: string;
changelogVersionMessage?: string;
changelogPreset?: string;
changelogIncludeCommitAuthorFullname?: boolean | string;
changelogIncludeCommitsGitAuthor?: boolean | string;
changelogIncludeCommitsClientLogin?: boolean | string;
commitsSinceLastRelease?: RemoteCommit[];
rootPath?: string;
tagPrefix?: string;
version?: string;

/** @deprecated this option was renamed to `changelogIncludeCommitsGitAuthor` */
changelogIncludeCommitAuthorFullname?: boolean | string;
}

export interface FetchConfig {
Expand Down
8 changes: 4 additions & 4 deletions packages/version/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Running `lerna version --conventional-commits` without the above flags will rele
- [`--conventional-commits`](#--conventional-commits)
- [`--conventional-graduate`](#--conventional-graduate)
- [`--conventional-prerelease`](#--conventional-prerelease)
- [`--changelog-include-commit-author-fullname [msg]`](#--changelog-include-commit-author-fullname-msg) (new)
- [`--changelog-include-commits-git-author [msg]`](#--changelog-include-commits-git-author-msg) (new)
- [`--changelog-include-commits-client-login [msg]`](#--changelog-include-commits-client-login-msg) (new)
- [`--changelog-header-message <msg>`](#--changelog-header-message-msg) (new)
- [`--changelog-version-message <msg>`](#--changelog-version-message-msg) (new)
Expand Down Expand Up @@ -232,19 +232,19 @@ lerna version --conventional-commits --conventional-prerelease

When run with this flag, `lerna version` will release with prerelease versions the specified packages (comma-separated) or all packages using `*`. Releases all unreleased changes as pre(patch/minor/major/release) by prefixing the version recommendation from `conventional-commits` with `pre`, eg. if present changes include a feature commit, the recommended bump will be `minor`, so this flag will result in a `preminor` release. If changes are present for packages that are not specified (if specifying packages), or for packages that are already in prerelease, those packages will be versioned as they normally would using `--conventional-commits`.

### `--changelog-include-commit-author-fullname [msg]`
### `--changelog-include-commits-git-author [msg]`
Specify if we want to include the git commit author's name, appended to the end of each changelog commit entry, this is only available when using `--conventional-commits` with changelogs enabled. The default format will be appending the git commit author name at the end of each commit entry, we could also use a custom format by providing the `%a` token, see examples below.

> **Note** that the author name is the name that was provided in the user's Git config, for more info please refer to [Git Configuration](https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration). Also note, that is **not** the same as for example a GitHub login username, Git does not store such information in its commit history.
```sh
# default format, without any argument
# will add the author name wrapped in (...) and appended to the commit line entry
lerna version --conventional-commits --changelog-include-commit-author-fullname
lerna version --conventional-commits --changelog-include-commits-git-author
# **deps:** update dependency git-url-parse to v12 ([978bf36](https://github.com/.../978bf36)) (Whitesource Renovate)

# custom format with %a token
lerna version --conventional-commits --changelog-include-commit-author-fullname " (by _%a_)"
lerna version --conventional-commits --changelog-include-commits-git-author " (by _%a_)"
# **deps:** update dependency git-url-parse to v12 ([978bf36](https://github.com/.../978bf36)) (by _Whitesource Renovate_)
```

Expand Down
19 changes: 16 additions & 3 deletions packages/version/src/__tests__/version-command.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,27 @@ describe('VersionCommand', () => {
);
});

it('throws an error if --changelog-include-commits-client-login and --changelog-include-commit-author-fullname flags are both passed', async () => {
it('throws an error if --changelog-include-commits-client-login and --changelog-include-commits-git-author flags are both passed', async () => {
const testDir = await initFixture('normal');
const command = new VersionCommand(
createArgv(testDir, '--changelog-include-commits-client-login', '--changelog-include-commit-author-fullname')
createArgv(testDir, '--changelog-include-commits-client-login', '--changelog-include-commits-git-author')
);

await expect(command).rejects.toThrow(
'--changelog-include-commits-client-login cannot be combined with --changelog-include-commit-author-fullname.'
'--changelog-include-commits-client-login cannot be combined with --changelog-include-commits-git-author.'
);
});

it('shows a log warning when using previous option --changelog-include-commit-author-fullname since it was renamed.', async () => {
const testDir = await initFixture('normal');
const command = new VersionCommand(createArgv(testDir, '--changelog-include-commit-author-fullname'));
await command;
const loggerSpy = jest.spyOn(command.logger, 'warn');
command.initialize();

expect(loggerSpy).toHaveBeenCalledWith(
'deprecated',
'--changelog-include-commit-author-fullname has been renamed to --changelog-include-commits-git-author.'
);
});

Expand Down
17 changes: 12 additions & 5 deletions packages/version/src/version-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,22 @@ export class VersionCommand extends Command<VersionCommandOption> {
);
}

if (this.options.changelogIncludeCommitsClientLogin && this.options.changelogIncludeCommitAuthorFullname) {
if (this.options.changelogIncludeCommitsClientLogin && this.options.changelogIncludeCommitsGitAuthor) {
throw new ValidationError(
'ENOTALLOWED',
dedent`
--changelog-include-commits-client-login cannot be combined with --changelog-include-commit-author-fullname.
--changelog-include-commits-client-login cannot be combined with --changelog-include-commits-git-author.
`
);
}

if (this.options.changelogIncludeCommitAuthorFullname) {
this.logger.warn(
'deprecated',
'--changelog-include-commit-author-fullname has been renamed to --changelog-include-commits-git-author.'
);
}

// 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;
Expand Down Expand Up @@ -571,7 +578,7 @@ export class VersionCommand extends Command<VersionCommandOption> {
const {
conventionalCommits,
changelogPreset,
changelogIncludeCommitAuthorFullname,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
Expand Down Expand Up @@ -642,7 +649,7 @@ export class VersionCommand extends Command<VersionCommandOption> {
changelogPreset,
rootPath,
tagPrefix: this.tagPrefix,
changelogIncludeCommitAuthorFullname,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
Expand Down Expand Up @@ -726,7 +733,7 @@ export class VersionCommand extends Command<VersionCommandOption> {
rootPath,
tagPrefix: this.tagPrefix,
version: this.globalVersion,
changelogIncludeCommitAuthorFullname,
changelogIncludeCommitsGitAuthor,
changelogIncludeCommitsClientLogin,
changelogHeaderMessage,
changelogVersionMessage,
Expand Down

0 comments on commit b095637

Please sign in to comment.