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 includeCommitId option #325

Merged
merged 2 commits into from
Jun 21, 2022
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
10 changes: 10 additions & 0 deletions docs/configuration/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
9 changes: 7 additions & 2 deletions packages/melos/lib/src/common/changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(')');
}

Expand Down
14 changes: 14 additions & 0 deletions packages/melos/lib/src/workspace_configs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class VersionCommandConfigs {
const VersionCommandConfigs({
this.message,
this.linkToCommits,
this.includeCommitId,
this.branch,
this.workspaceChangelog = false,
this.updateGitTagRefs = false,
Expand All @@ -267,6 +268,11 @@ class VersionCommandConfigs {
map: yaml,
path: 'command/version',
);
final includeCommitId = assertKeyIsA<bool?>(
key: 'includeCommitId',
map: yaml,
path: 'command/version',
);
final branch = assertKeyIsA<String?>(
key: 'branch',
map: yaml,
Expand All @@ -288,6 +294,7 @@ class VersionCommandConfigs {
return VersionCommandConfigs(
branch: branch,
linkToCommits: linkToCommits,
includeCommitId: includeCommitId,
message: message,
workspaceChangelog: workspaceChangelog ?? false,
updateGitTagRefs: updateGitTagRefs ?? false,
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -337,6 +349,7 @@ class VersionCommandConfigs {
runtimeType.hashCode ^
message.hashCode ^
linkToCommits.hashCode ^
includeCommitId.hashCode ^
workspaceChangelog.hashCode ^
updateGitTagRefs.hashCode ^
branch.hashCode;
Expand All @@ -347,6 +360,7 @@ class VersionCommandConfigs {
VersionCommandConfigs(
message: $message,
linkToCommits: $linkToCommits,
includeCommitId: $includeCommitId,
workspaceChangelog: $workspaceChangelog,
updateGitTagRefs: $updateGitTagRefs,
branch: $branch,
Expand Down
36 changes: 35 additions & 1 deletion packages/melos/test/changelog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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']!;
Expand All @@ -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(
'''
Expand Down