startBuild method
Starts new build for Application by its appId
, workflowId
and branch
Implementation
Future<ApiResponse<BuildResponse>> startBuild(
String appId,
String workflowId,
String branch,
) async {
try {
final request = await _client.postUrl(Uri.parse("$apiUrl/builds"));
request.headers.add(HttpHeaders.authorizationHeader, 'Bearer $authKey');
request.headers.contentType = ContentType(
"application",
"json",
charset: "utf-8",
);
final data = {
'appId': '$appId',
'workflowId': '$workflowId',
'branch': '$branch',
};
request.write(jsonEncode(data));
final response = await request.close();
if (response.statusCode == HttpStatus.ok) {
final data = await utf8.decoder.bind(response).join();
final json = jsonDecode(data);
final builds = BuildResponse.fromJson(json);
return ApiResponse(wasSuccessful: true, data: builds);
}
return ApiResponse(
wasSuccessful: false,
error: 'Response code was ${response.statusCode}',
);
} catch (e) {
print(e);
return ApiResponse(wasSuccessful: false, error: 'Unknown error');
}
}