Compare commits

..

1 Commits

Author SHA1 Message Date
Jef Roosens e2331159d6
wip [CI SKIP]
ci/woodpecker/pr/test Pipeline is pending Details
ci/woodpecker/pr/lint Pipeline failed Details
ci/woodpecker/pr/docker unknown status Details
ci/woodpecker/pr/man unknown status Details
ci/woodpecker/pr/docs Pipeline failed Details
ci/woodpecker/pr/build Pipeline failed Details
2022-12-16 18:18:25 +01:00
3 changed files with 19 additions and 16 deletions

View File

@ -58,8 +58,8 @@ pub fn (mut m ImageManager) up_to_date(base_image string) bool {
} }
// If the inspect fails, it's either because the image doesn't exist or // If the inspect fails, it's either because the image doesn't exist or
// because of some other error. Either way, we can't know *for certain* // because of some other error. Either we can't know *for certain* that
// that the image exists, so we return false. // the image exists, so we return false.
return false return false
} }

View File

@ -59,6 +59,11 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
res := c.send_request_raw(method, url, params, body)! res := c.send_request_raw(method, url, params, body)!
status := res.status() status := res.status()
// Just return an empty successful response
if status.is_success() && res.body == '' {
return new_data_response(T{})
}
// Non-successful requests are expected to return either an empty body or // Non-successful requests are expected to return either an empty body or
// Response<string> // Response<string>
if status.is_error() { if status.is_error() {
@ -72,11 +77,6 @@ fn (c &Client) send_request_with_body<T>(method Method, url string, params map[s
return error('Status $res.status_code ($status.str()): $data.message') return error('Status $res.status_code ($status.str()): $data.message')
} }
// Just return an empty successful response
if res.body == '' {
return new_data_response(T{})
}
data := json.decode(Response<T>, res.body)! data := json.decode(Response<T>, res.body)!
return data return data

View File

@ -13,7 +13,7 @@ struct Config {
base_image string = 'archlinux:base-devel' base_image string = 'archlinux:base-devel'
} }
// cmd returns the cli submodule that handles the targets API interaction // cmd returns the cli submodule that handles the repos API interaction
pub fn cmd() cli.Command { pub fn cmd() cli.Command {
return cli.Command{ return cli.Command{
name: 'targets' name: 'targets'
@ -236,11 +236,14 @@ pub fn cmd() cli.Command {
} }
} }
// get_repo_by_prefix tries to find the repo with the given prefix in its
// ID. If multiple or none are found, an error is raised.
// list prints out a list of all repositories. // list prints out a list of all repositories.
fn list(conf Config, filter TargetFilter, raw bool) ! { fn list(conf Config, filter TargetFilter, raw bool) ! {
c := client.new(conf.address, conf.api_key) c := client.new(conf.address, conf.api_key)
targets := c.get_targets(filter)! repos := c.get_targets(filter)!
data := targets.map([it.id.str(), it.kind, it.url, it.repo]) data := repos.map([it.id.str(), it.kind, it.url, it.repo])
if raw { if raw {
println(console.tabbed_table(data)) println(console.tabbed_table(data))
@ -249,7 +252,7 @@ fn list(conf Config, filter TargetFilter, raw bool) ! {
} }
} }
// add adds a new target to the server's list. // add adds a new repository to the server's list.
fn add(conf Config, t &NewTarget, raw bool) ! { fn add(conf Config, t &NewTarget, raw bool) ! {
c := client.new(conf.address, conf.api_key) c := client.new(conf.address, conf.api_key)
target_id := c.add_target(t)! target_id := c.add_target(t)!
@ -261,13 +264,13 @@ fn add(conf Config, t &NewTarget, raw bool) ! {
} }
} }
// remove removes a target from the server's list. // remove removes a repository from the server's list.
fn remove(conf Config, id string) ! { fn remove(conf Config, id string) ! {
c := client.new(conf.address, conf.api_key) c := client.new(conf.address, conf.api_key)
c.remove_target(id.int())! c.remove_target(id.int())!
} }
// patch patches a given target with the provided params. // patch patches a given repository with the provided params.
fn patch(conf Config, id string, params map[string]string) ! { fn patch(conf Config, id string, params map[string]string) ! {
// We check the cron expression first because it's useless to send an // We check the cron expression first because it's useless to send an
// invalid one to the server. // invalid one to the server.
@ -281,9 +284,9 @@ fn patch(conf Config, id string, params map[string]string) ! {
c.patch_target(id.int(), params)! c.patch_target(id.int(), params)!
} }
// info shows detailed information for a given target. // info shows detailed information for a given repo.
fn info(conf Config, id string) ! { fn info(conf Config, id string) ! {
c := client.new(conf.address, conf.api_key) c := client.new(conf.address, conf.api_key)
target := c.get_target(id.int())! repo := c.get_target(id.int())!
println(target) println(repo)
} }