chore: some final revisions before pr merge

renovate/rouge-4.x
Jef Roosens 2022-12-16 18:18:25 +01:00 committed by Jef Roosens
parent af4c9e1d00
commit fe3e6e2bab
3 changed files with 21 additions and 24 deletions

View File

@ -33,9 +33,9 @@ pub fn (m &ImageManager) get(base_image string) string {
return m.images[base_image].last()
}
// up_to_date returns whether the last known builder image is exists and is up
// to date. If this function returns true, the last builder image may be used
// to perform a build.
// up_to_date returns true if the last known builder image exists and is up to
// date. If this function returns true, the last builder image may be used to
// perform a build.
pub fn (mut m ImageManager) up_to_date(base_image string) bool {
if base_image !in m.timestamps
|| m.timestamps[base_image].add_seconds(m.max_image_age) <= time.now() {
@ -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
// because of some other error. Either we can't know *for certain* that
// the image exists, so we return false.
// because of some other error. Either way, we can't know *for certain*
// that the image exists, so we return false.
return false
}
@ -67,7 +67,7 @@ pub fn (mut m ImageManager) up_to_date(base_image string) bool {
}
// refresh_image builds a new builder image from the given base image. This
// function should only be called if `up_to_date` return false.
// function should only be called if `up_to_date` returned false.
fn (mut m ImageManager) refresh_image(base_image string) ! {
// TODO use better image tags for built images
new_image := build.create_build_image(base_image) or {

View File

@ -57,12 +57,7 @@ fn (c &Client) send_request<T>(method Method, url string, params map[string]stri
// output as a Response<T> object.
fn (c &Client) send_request_with_body<T>(method Method, url string, params map[string]string, body string) !Response<T> {
res := c.send_request_raw(method, url, params, body)!
status := http.status_from_int(res.status_code)
// Just return an empty successful response
if status.is_success() && res.body == '' {
return new_data_response(T{})
}
status := res.status()
// Non-successful requests are expected to return either an empty body or
// Response<string>
@ -77,6 +72,11 @@ 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')
}
// Just return an empty successful response
if res.body == '' {
return new_data_response(T{})
}
data := json.decode(Response<T>, res.body)!
return data

View File

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