Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option that allows to include commit bodies in changelog #606

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading