From 524e58a1d2c72d39b62e355997d06134c9342b53 Mon Sep 17 00:00:00 2001 From: Andrei Lesnitsky Date: Fri, 1 Dec 2023 14:31:45 +0100 Subject: [PATCH] feat: add option that allows to include commit bodies in changelog (#606) --- packages/melos/lib/src/common/changelog.dart | 17 +++++++++++ packages/melos/lib/src/workspace_configs.dart | 29 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/packages/melos/lib/src/common/changelog.dart b/packages/melos/lib/src/common/changelog.dart index e522b846..e9eef4f6 100644 --- a/packages/melos/lib/src/common/changelog.dart +++ b/packages/melos/lib/src/common/changelog.dart @@ -194,6 +194,23 @@ extension ChangelogStringBufferExtension on StringBuffer { } writeln(); + + final version = update.workspace.config.commands.version; + + if (!version.includeCommitBody) continue; + if (parsedMessage.body == null) continue; + + final shouldWriteBody = + !version.commitBodyOnlyBreaking || parsedMessage.isBreakingChange; + + if (shouldWriteBody) { + writeln(); + for (final line in parsedMessage.body!.split('\n')) { + write(' ' * 4); + writeln(line); + } + writeln(); + } } writeln(); } diff --git a/packages/melos/lib/src/workspace_configs.dart b/packages/melos/lib/src/workspace_configs.dart index 9c7b0afc..fd39c572 100644 --- a/packages/melos/lib/src/workspace_configs.dart +++ b/packages/melos/lib/src/workspace_configs.dart @@ -606,6 +606,8 @@ class VersionCommandConfigs { this.includeScopes = true, this.linkToCommits = false, this.includeCommitId = false, + this.includeCommitBody = false, + this.commitBodyOnlyBreaking = true, this.updateGitTagRefs = false, this.releaseUrl = false, List? aggregateChangelogs, @@ -726,11 +728,32 @@ class VersionCommandConfigs { ) : VersionLifecycleHooks.empty; + final changelogCommitBodiesEntry = assertKeyIsA?>( + key: 'changelogCommitBodies', + map: yaml, + path: 'command/version', + ) ?? + const {}; + + final includeCommitBodies = assertKeyIsA( + key: 'include', + map: changelogCommitBodiesEntry, + path: 'command/version/changelogCommitBodies', + ); + + final bodiesOnlyBreaking = assertKeyIsA( + key: 'onlyBreaking', + map: changelogCommitBodiesEntry, + path: 'command/version/changelogCommitBodies', + ); + return VersionCommandConfigs( branch: branch, message: message, includeScopes: includeScopes ?? true, includeCommitId: includeCommitId ?? false, + includeCommitBody: includeCommitBodies ?? false, + commitBodyOnlyBreaking: bodiesOnlyBreaking ?? true, linkToCommits: linkToCommits ?? repositoryIsConfigured, updateGitTagRefs: updateGitTagRefs ?? false, releaseUrl: releaseUrl ?? false, @@ -756,6 +779,12 @@ class VersionCommandConfigs { /// Whether to add commits ids in the generated CHANGELOG.md. final bool includeCommitId; + /// Wheter to include commit bodies in the generated CHANGELOG.md. + final bool includeCommitBody; + + /// Whether to only include commit bodies for breaking changes. + final bool commitBodyOnlyBreaking; + /// Whether to add links to commits in the generated CHANGELOG.md. final bool linkToCommits;