VersionCommandConfigs.fromYaml constructor

VersionCommandConfigs.fromYaml(
  1. Map<Object?, Object?> yaml, {
  2. required String workspacePath,
})

Implementation

factory VersionCommandConfigs.fromYaml(
  Map<Object?, Object?> yaml, {
  required String workspacePath,
}) {
  final branch = assertKeyIsA<String?>(
    key: 'branch',
    map: yaml,
    path: 'command/version',
  );
  final message = assertKeyIsA<String?>(
    key: 'message',
    map: yaml,
    path: 'command/version',
  );
  final includeScopes = assertKeyIsA<bool?>(
    key: 'includeScopes',
    map: yaml,
    path: 'command/version',
  );
  final includeCommitId = assertKeyIsA<bool?>(
    key: 'includeCommitId',
    map: yaml,
    path: 'command/version',
  );
  final linkToCommits = assertKeyIsA<bool?>(
    key: 'linkToCommits',
    map: yaml,
    path: 'command/version',
  );
  final updateGitTagRefs = assertKeyIsA<bool?>(
    key: 'updateGitTagRefs',
    map: yaml,
    path: 'command/version',
  );
  final releaseUrl = assertKeyIsA<bool?>(
    key: 'releaseUrl',
    map: yaml,
    path: 'command/version',
  );

  final workspaceChangelog = assertKeyIsA<bool?>(
    key: 'workspaceChangelog',
    map: yaml,
    path: 'command/version',
  );

  final aggregateChangelogs = <AggregateChangelogConfig>[];
  if (workspaceChangelog ?? false) {
    aggregateChangelogs.add(AggregateChangelogConfig.workspace());
  }

  final changelogsYaml = assertKeyIsA<List<dynamic>?>(
    key: 'changelogs',
    map: yaml,
    path: 'command/version',
  );

  for (var i = 0; i < (changelogsYaml?.length ?? 0); i++) {
    final entry = changelogsYaml?[i] as Map;

    final path = assertKeyIsA<String>(
      map: entry,
      path: 'command/version/changelogs[$i]',
      key: 'path',
    );

    final packageFilterMap = assertKeyIsA<Map<Object?, Object?>>(
      map: entry,
      key: 'packageFilters',
      path: 'command/version/changelogs[$i]',
    );
    final packageFilter = PackageFilter.fromYaml(
      packageFilterMap,
      path: 'command/version/changelogs[$i]',
      workspacePath: workspacePath,
    );

    final description = assertKeyIsA<String?>(
      map: entry,
      path: 'command/version/changelogs[$i]',
      key: 'description',
    );
    final changelogConfig = AggregateChangelogConfig(
      path: path,
      packageFilter: packageFilter,
      description: description,
    );

    aggregateChangelogs.add(changelogConfig);
  }

  return VersionCommandConfigs(
    branch: branch,
    message: message,
    includeScopes: includeScopes ?? false,
    includeCommitId: includeCommitId,
    linkToCommits: linkToCommits,
    updateGitTagRefs: updateGitTagRefs ?? false,
    releaseUrl: releaseUrl ?? false,
    aggregateChangelogs: aggregateChangelogs,
  );
}