Skip to content

Commit

Permalink
feat: add option that allows to include commit bodies in changelog (#606
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lesnitsky authored Dec 1, 2023
1 parent 69dda57 commit 524e58a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/melos/lib/src/common/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
29 changes: 29 additions & 0 deletions packages/melos/lib/src/workspace_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<AggregateChangelogConfig>? aggregateChangelogs,
Expand Down Expand Up @@ -726,11 +728,32 @@ class VersionCommandConfigs {
)
: VersionLifecycleHooks.empty;

final changelogCommitBodiesEntry = assertKeyIsA<Map<Object?, Object?>?>(
key: 'changelogCommitBodies',
map: yaml,
path: 'command/version',
) ??
const {};

final includeCommitBodies = assertKeyIsA<bool?>(
key: 'include',
map: changelogCommitBodiesEntry,
path: 'command/version/changelogCommitBodies',
);

final bodiesOnlyBreaking = assertKeyIsA<bool?>(
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,
Expand All @@ -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;

Expand Down

0 comments on commit 524e58a

Please sign in to comment.