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 }
|
|
|
|
import response { Response }
|
|
|
|
import time
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_logs returns all build logs.
|
2022-05-29 21:07:46 +02:00
|
|
|
pub fn (c &Client) get_build_logs(filter BuildLogFilter) ?Response<[]BuildLog> {
|
|
|
|
params := models.params_from(filter)
|
|
|
|
data := c.send_request<[]BuildLog>(Method.get, '/api/logs', params)?
|
2022-05-07 19:38:28 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_logs_for_repo returns all build logs for a given repo.
|
2022-05-07 19:38:28 +02:00
|
|
|
pub fn (c &Client) get_build_logs_for_repo(repo_id int) ?Response<[]BuildLog> {
|
|
|
|
params := {
|
|
|
|
'repo': repo_id.str()
|
|
|
|
}
|
|
|
|
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<[]BuildLog>(Method.get, '/api/logs', params)?
|
2022-05-07 19:38:28 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_log returns a specific build log.
|
2022-05-07 19:38:28 +02:00
|
|
|
pub fn (c &Client) get_build_log(id int) ?Response<BuildLog> {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<BuildLog>(Method.get, '/api/logs/$id', {})?
|
2022-05-07 19:38:28 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_build_log_content returns the contents of the build log file.
|
2022-05-07 21:50:20 +02:00
|
|
|
pub fn (c &Client) get_build_log_content(id int) ?string {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request_raw_response(Method.get, '/api/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-05-07 19:38:28 +02:00
|
|
|
pub fn (c &Client) add_build_log(repo_id int, start_time time.Time, end_time time.Time, arch string, exit_code int, content string) ?Response<string> {
|
|
|
|
params := {
|
|
|
|
'repo': repo_id.str()
|
|
|
|
'startTime': start_time.str()
|
|
|
|
'endTime': end_time.str()
|
|
|
|
'arch': arch
|
|
|
|
'exitCode': exit_code.str()
|
|
|
|
}
|
|
|
|
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request_with_body<string>(Method.post, '/api/logs', params, content)?
|
2022-05-07 19:38:28 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|