feat: made arch param optional when adding Git repo

cron-docs
Jef Roosens 2022-05-01 12:44:54 +02:00
parent d9d7272b44
commit b1ac39e234
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 20 additions and 8 deletions

View File

@ -26,14 +26,14 @@ pub fn cmd() cli.Command {
},
cli.Command{
name: 'add'
required_args: 4
usage: 'url branch repo arch...'
required_args: 3
usage: 'url branch repo'
description: 'Add a new repository.'
execute: fn (cmd cli.Command) ? {
config_file := cmd.flags.get_string('config-file') ?
conf := env.load<Config>(config_file) ?
add(conf, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3..]) ?
add(conf, cmd.args[0], cmd.args[1], cmd.args[2]) ?
}
},
cli.Command{
@ -130,8 +130,8 @@ fn list(conf Config) ? {
}
// add adds a new repository to the server's list.
fn add(conf Config, url string, branch string, repo string, arch []string) ? {
res := add_repo(conf.address, conf.api_key, url, branch, repo, arch) ?
fn add(conf Config, url string, branch string, repo string) ? {
res := add_repo(conf.address, conf.api_key, url, branch, repo, []) ?
println(res.message)
}

View File

@ -35,12 +35,16 @@ pub fn get_repos(address string, api_key string) ?map[string]GitRepo {
// add_repo adds a new repo to the server.
pub fn add_repo(address string, api_key string, url string, branch string, repo string, arch []string) ?Response<string> {
params := {
mut params := {
'url': url
'branch': branch
'repo': repo
'arch': arch.join(',')
}
if arch.len > 0 {
params['arch'] = arch.join(',')
}
data := send_request<string>(http.Method.post, address, '/api/repos', api_key, params) ?
return data

View File

@ -57,7 +57,15 @@ fn (mut app App) post_repo() web.Result {
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
}
new_repo := git.repo_from_params(app.query) or {
mut params := app.query.clone()
// If a repo is created without specifying the arch, we assume it's meant
// for the default architecture.
if 'arch' !in params {
params['arch'] = app.conf.default_arch
}
new_repo := git.repo_from_params(params) or {
return app.json(http.Status.bad_request, new_response(err.msg()))
}