2022-05-07 19:38:28 +02:00
|
|
|
module client
|
|
|
|
|
2022-05-29 21:07:46 +02:00
|
|
|
import models { BuildLog, BuildLogFilter }
|
2022-05-07 19:38:28 +02:00
|
|
|
import net.http { Method }
|
2022-08-13 13:16:31 +02:00
|
|
|
import web.response { Response }
|
2022-05-07 19:38:28 +02:00
|
|
|
import time
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_logs returns all build logs.
|
2022-12-15 10:01:45 +01:00
|
|
|
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ![]BuildLog {
|
2022-05-29 21:07:46 +02:00
|
|
|
params := models.params_from(filter)
|
2022-11-01 21:10:45 +01:00
|
|
|
data := c.send_request<[]BuildLog>(Method.get, '/api/v1/logs', params)!
|
2022-05-07 19:38:28 +02:00
|
|
|
|
2022-12-15 10:01:45 +01:00
|
|
|
return data.data
|
2022-05-07 19:38:28 +02:00
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_log returns a specific build log.
|
2022-12-15 10:01:45 +01:00
|
|
|
pub fn (c &Client) get_build_log(id int) !BuildLog {
|
2022-11-01 21:10:45 +01:00
|
|
|
data := c.send_request<BuildLog>(Method.get, '/api/v1/logs/$id', {})!
|
2022-05-07 19:38:28 +02:00
|
|
|
|
2022-12-15 10:01:45 +01:00
|
|
|
return data.data
|
2022-05-07 19:38:28 +02:00
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_log_content returns the contents of the build log file.
|
2022-11-01 21:10:45 +01:00
|
|
|
pub fn (c &Client) get_build_log_content(id int) !string {
|
|
|
|
data := c.send_request_raw_response(Method.get, '/api/v1/logs/$id/content', {}, '')!
|
2022-05-07 21:50:20 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// add_build_log adds a new build log to the server.
|
2022-11-01 21:10:45 +01:00
|
|
|
pub fn (c &Client) add_build_log(target_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) !Response<int> {
|
2022-05-07 19:38:28 +02:00
|
|
|
params := {
|
2022-06-16 18:10:05 +02:00
|
|
|
'target': target_id.str()
|
2022-06-04 12:11:51 +02:00
|
|
|
'startTime': start_time.unix_time().str()
|
|
|
|
'endTime': end_time.unix_time().str()
|
2022-05-07 19:38:28 +02:00
|
|
|
'arch': arch
|
|
|
|
'exitCode': exit_code.str()
|
|
|
|
}
|
|
|
|
|
2022-11-01 21:10:45 +01:00
|
|
|
data := c.send_request_with_body<int>(Method.post, '/api/v1/logs', params, content)!
|
2022-05-07 19:38:28 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
2022-12-17 16:24:01 +01:00
|
|
|
|
|
|
|
// remove_build_log removes the build log with the given id from the server.
|
|
|
|
pub fn (c &Client) remove_build_log(id int) !string {
|
|
|
|
data := c.send_request<string>(.delete, '/api/v1/logs/$id', {})!
|
|
|
|
|
|
|
|
return data.data
|
|
|
|
}
|