refactor: renamed codebase to "targets"

This commit is contained in:
Jef Roosens 2022-06-14 22:25:40 +02:00 committed by Jef Roosens
parent faec08f846
commit 102a7f8899
Signed by untrusted user: Jef Roosens
GPG key ID: B580B976584B5F30
19 changed files with 205 additions and 191 deletions

View file

@ -13,10 +13,10 @@ pub fn (c &Client) get_build_logs(filter BuildLogFilter) ?Response<[]BuildLog> {
return data
}
// get_build_logs_for_repo returns all build logs for a given repo.
pub fn (c &Client) get_build_logs_for_repo(repo_id int) ?Response<[]BuildLog> {
// get_build_logs_for_target returns all build logs for a given target.
pub fn (c &Client) get_build_logs_for_target(target_id int) ?Response<[]BuildLog> {
params := {
'repo': repo_id.str()
'repo': target_id.str()
}
data := c.send_request<[]BuildLog>(Method.get, '/api/v1/logs', params)?

View file

@ -1,46 +1,46 @@
module client
import models { GitRepo, GitRepoFilter }
import models { Target, TargetFilter }
import net.http { Method }
import response { Response }
// get_targets returns a list of GitRepo's, given a filter object.
pub fn (c &Client) get_targets(filter GitRepoFilter) ?[]GitRepo {
// get_targets returns a list of targets, given a filter object.
pub fn (c &Client) get_targets(filter TargetFilter) ?[]Target {
params := models.params_from(filter)
data := c.send_request<[]GitRepo>(Method.get, '/api/v1/targets', params)?
data := c.send_request<[]Target>(Method.get, '/api/v1/targets', params)?
return data.data
}
// get_all_targets retrieves *all* GitRepo's from the API using the default
// get_all_targets retrieves *all* targs from the API using the default
// limit.
pub fn (c &Client) get_all_targets() ?[]GitRepo {
mut repos := []GitRepo{}
pub fn (c &Client) get_all_targets() ?[]Target {
mut targets := []Target{}
mut offset := u64(0)
for {
sub_repos := c.get_targets(offset: offset)?
sub_targets := c.get_targets(offset: offset)?
if sub_repos.len == 0 {
if sub_targets.len == 0 {
break
}
repos << sub_repos
targets << sub_targets
offset += u64(sub_repos.len)
offset += u64(sub_targets.len)
}
return repos
return targets
}
// get_target returns the repo for a specific ID.
pub fn (c &Client) get_target(id int) ?GitRepo {
data := c.send_request<GitRepo>(Method.get, '/api/v1/targets/$id', {})?
// get_target returns the target for a specific id.
pub fn (c &Client) get_target(id int) ?Target {
data := c.send_request<Target>(Method.get, '/api/v1/targets/$id', {})?
return data.data
}
// add_target adds a new repo to the server.
// add_target adds a new target to the server.
pub fn (c &Client) add_target(url string, branch string, repo string, arch []string) ?Response<string> {
mut params := {
'url': url
@ -57,14 +57,14 @@ pub fn (c &Client) add_target(url string, branch string, repo string, arch []str
return data
}
// remove_target removes the repo with the given ID from the server.
// remove_target removes the target with the given id from the server.
pub fn (c &Client) remove_target(id int) ?Response<string> {
data := c.send_request<string>(Method.delete, '/api/v1/targets/$id', {})?
return data
}
// patch_target sends a PATCH request to the given repo with the params as
// patch_target sends a PATCH request to the given target with the params as
// payload.
pub fn (c &Client) patch_target(id int, params map[string]string) ?Response<string> {
data := c.send_request<string>(Method.patch, '/api/v1/targets/$id', params)?