createRepository method

Future<ProjectRepository> createRepository({
  1. required String projectId,
  2. required String name,
  3. String description = '',
  4. Map<String, String> annotations = const {},
})

Implementation

Future<ProjectRepository> createRepository({
  required String projectId,
  required String name,
  String description = '',
  Map<String, String> annotations = const {},
}) async {
  final encodedProjectId = Uri.encodeComponent(projectId);
  final uri = Uri.parse('$baseUrl/accounts/projects/$encodedProjectId/repositories');
  final body = {'name': name, 'description': description, 'annotations': annotations};

  final response = await httpClient.post(uri, body: jsonEncode(body));

  if (response.statusCode >= 400) {
    throw MeshagentException(
      'Failed to create repository. '
      'Status code: ${response.statusCode}, body: ${response.body}',
    );
  }

  return ProjectRepository.fromJson(jsonDecode(response.body) as Map<String, dynamic>);
}