diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index f12ffdd17..aae7fd299 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -164,6 +164,16 @@ command: branch: main ``` +### `command/version/includeCommitId` + +Whether to add short commit id (no links) in the CHANGELOG.md, that is generated by `melos version`. + +```yaml +command: + version: + includeCommitId: true +``` + ### `command/version/linkToCommits` Whether to add links to commits in the CHANGELOG.md, that is generated by `melos version`. diff --git a/packages/melos/lib/src/common/changelog.dart b/packages/melos/lib/src/common/changelog.dart index 0bad0901c..7e0d4b394 100644 --- a/packages/melos/lib/src/common/changelog.dart +++ b/packages/melos/lib/src/common/changelog.dart @@ -147,6 +147,7 @@ extension ChangelogStringBufferExtension on StringBuffer { final config = update.workspace.config; final repository = config.repository; final linkToCommits = config.commands.version.linkToCommits ?? false; + final includeCommitId = config.commands.version.includeCommitId ?? false; String processCommitHeader(String header) => repository != null ? header.withIssueLinks(repository) : header; @@ -178,11 +179,15 @@ extension ChangelogStringBufferExtension on StringBuffer { writePunctuated(processCommitHeader(parsedMessage.description!)); } - if (linkToCommits) { + if (linkToCommits || includeCommitId) { final shortCommitId = commit.id.substring(0, 8); final commitUrl = repository!.commitUrl(commit.id); write(' ('); - writeLink(shortCommitId, uri: commitUrl.toString()); + if (linkToCommits) { + writeLink(shortCommitId, uri: commitUrl.toString()); + } else { + write(shortCommitId); + } write(')'); } diff --git a/packages/melos/lib/src/workspace_configs.dart b/packages/melos/lib/src/workspace_configs.dart index 6f49e1d5c..26c5be7cf 100644 --- a/packages/melos/lib/src/workspace_configs.dart +++ b/packages/melos/lib/src/workspace_configs.dart @@ -251,6 +251,7 @@ class VersionCommandConfigs { const VersionCommandConfigs({ this.message, this.linkToCommits, + this.includeCommitId, this.branch, this.workspaceChangelog = false, this.updateGitTagRefs = false, @@ -267,6 +268,11 @@ class VersionCommandConfigs { map: yaml, path: 'command/version', ); + final includeCommitId = assertKeyIsA( + key: 'includeCommitId', + map: yaml, + path: 'command/version', + ); final branch = assertKeyIsA( key: 'branch', map: yaml, @@ -288,6 +294,7 @@ class VersionCommandConfigs { return VersionCommandConfigs( branch: branch, linkToCommits: linkToCommits, + includeCommitId: includeCommitId, message: message, workspaceChangelog: workspaceChangelog ?? false, updateGitTagRefs: updateGitTagRefs ?? false, @@ -302,6 +309,9 @@ class VersionCommandConfigs { /// Whether to add links to commits in the generated CHANGELOG.md. final bool? linkToCommits; + /// Whether to add commits ids in the generated CHANGELOG.md. + final bool? includeCommitId; + /// Whether to also generate a CHANGELOG.md for the entire workspace at the root. final bool workspaceChangelog; @@ -316,6 +326,7 @@ class VersionCommandConfigs { return { if (message != null) 'message': message, if (linkToCommits != null) 'linkToCommits': linkToCommits, + if (includeCommitId != null) 'includeCommitId': includeCommitId, if (branch != null) 'branch': branch, 'workspaceChangelog': workspaceChangelog, 'updateGitTagRefs': updateGitTagRefs, @@ -328,6 +339,7 @@ class VersionCommandConfigs { runtimeType == other.runtimeType && other.message == message && other.linkToCommits == linkToCommits && + other.includeCommitId == includeCommitId && other.workspaceChangelog == workspaceChangelog && other.updateGitTagRefs == updateGitTagRefs && other.branch == branch; @@ -337,6 +349,7 @@ class VersionCommandConfigs { runtimeType.hashCode ^ message.hashCode ^ linkToCommits.hashCode ^ + includeCommitId.hashCode ^ workspaceChangelog.hashCode ^ updateGitTagRefs.hashCode ^ branch.hashCode; @@ -347,6 +360,7 @@ class VersionCommandConfigs { VersionCommandConfigs( message: $message, linkToCommits: $linkToCommits, + includeCommitId: $includeCommitId, workspaceChangelog: $workspaceChangelog, updateGitTagRefs: $updateGitTagRefs, branch: $branch, diff --git a/packages/melos/test/changelog_test.dart b/packages/melos/test/changelog_test.dart index 4eb5e4f1a..c4839816f 100644 --- a/packages/melos/test/changelog_test.dart +++ b/packages/melos/test/changelog_test.dart @@ -38,6 +38,36 @@ void main() { }); }); + group('includeCommitId', () { + test('when enabled, adds commit id behind each one', () { + final workspace = buildWorkspaceWithRepository( + includeCommitId: true, + linkToCommits: false, + ); + final package = workspace.allPackages['test_pkg']!; + final commit = testCommit(message: 'feat(a): b'); + + expect( + renderCommitPackageUpdate(workspace, package, commit), + contains('**FEAT**: b. (${commit.id.substring(0, 8)})'), + ); + }); + + test( + 'when enabled, and linkToCommits is also enabled adds link to commit behind each one', + () { + final workspace = buildWorkspaceWithRepository(includeCommitId: true); + final package = workspace.allPackages['test_pkg']!; + final commit = testCommit(message: 'feat(a): b'); + final commitUrl = workspace.config.repository!.commitUrl(commit.id); + + expect( + renderCommitPackageUpdate(workspace, package, commit), + contains('**FEAT**: b. ([${commit.id.substring(0, 8)}]($commitUrl))'), + ); + }); + }); + test('when repository is specified, adds links to referenced issues/PRs', () { final workspace = buildWorkspaceWithRepository(linkToCommits: false); final package = workspace.allPackages['test_pkg']!; @@ -51,13 +81,17 @@ void main() { }); } -MelosWorkspace buildWorkspaceWithRepository({bool linkToCommits = true}) { +MelosWorkspace buildWorkspaceWithRepository({ + bool linkToCommits = true, + bool includeCommitId = false, +}) { final workspaceBuilder = VirtualWorkspaceBuilder( ''' repository: https://github.com/a/b command: version: linkToCommits: $linkToCommits + includeCommitId: $includeCommitId ''', )..addPackage( '''