2022-05-07 16:10:27 +02:00
|
|
|
module client
|
|
|
|
|
2022-05-07 19:38:28 +02:00
|
|
|
import db { GitRepo }
|
|
|
|
import net.http { Method }
|
2022-05-07 16:10:27 +02:00
|
|
|
import response { Response }
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_git_repos returns the current list of repos.
|
2022-05-07 19:38:28 +02:00
|
|
|
pub fn (c &Client) get_git_repos() ?[]GitRepo {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<[]GitRepo>(Method.get, '/api/repos', {})?
|
2022-05-07 16:10:27 +02:00
|
|
|
|
|
|
|
return data.data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// get_git_repo returns the repo for a specific ID.
|
2022-05-07 19:38:28 +02:00
|
|
|
pub fn (c &Client) get_git_repo(id int) ?GitRepo {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<GitRepo>(Method.get, '/api/repos/$id', {})?
|
2022-05-07 16:10:27 +02:00
|
|
|
|
|
|
|
return data.data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// add_git_repo adds a new repo to the server.
|
2022-05-07 16:10:27 +02:00
|
|
|
pub fn (c &Client) add_git_repo(url string, branch string, repo string, arch []string) ?Response<string> {
|
|
|
|
mut params := {
|
|
|
|
'url': url
|
|
|
|
'branch': branch
|
|
|
|
'repo': repo
|
|
|
|
}
|
|
|
|
|
|
|
|
if arch.len > 0 {
|
|
|
|
params['arch'] = arch.join(',')
|
|
|
|
}
|
|
|
|
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<string>(Method.post, '/api/repos', params)?
|
2022-05-07 16:10:27 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// remove_git_repo removes the repo with the given ID from the server.
|
2022-05-07 16:10:27 +02:00
|
|
|
pub fn (c &Client) remove_git_repo(id int) ?Response<string> {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<string>(Method.delete, '/api/repos/$id', {})?
|
2022-05-07 16:10:27 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
2022-05-07 22:06:17 +02:00
|
|
|
// patch_git_repo sends a PATCH request to the given repo with the params as
|
2022-05-07 16:10:27 +02:00
|
|
|
// payload.
|
|
|
|
pub fn (c &Client) patch_git_repo(id int, params map[string]string) ?Response<string> {
|
2022-05-14 20:06:08 +02:00
|
|
|
data := c.send_request<string>(Method.patch, '/api/repos/$id', params)?
|
2022-05-07 16:10:27 +02:00
|
|
|
|
|
|
|
return data
|
|
|
|
}
|