feat: made arch param optional when adding Git repo
parent
d9d7272b44
commit
b1ac39e234
|
@ -26,14 +26,14 @@ pub fn cmd() cli.Command {
|
||||||
},
|
},
|
||||||
cli.Command{
|
cli.Command{
|
||||||
name: 'add'
|
name: 'add'
|
||||||
required_args: 4
|
required_args: 3
|
||||||
usage: 'url branch repo arch...'
|
usage: 'url branch repo'
|
||||||
description: 'Add a new repository.'
|
description: 'Add a new repository.'
|
||||||
execute: fn (cmd cli.Command) ? {
|
execute: fn (cmd cli.Command) ? {
|
||||||
config_file := cmd.flags.get_string('config-file') ?
|
config_file := cmd.flags.get_string('config-file') ?
|
||||||
conf := env.load<Config>(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{
|
cli.Command{
|
||||||
|
@ -130,8 +130,8 @@ fn list(conf Config) ? {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add adds a new repository to the server's list.
|
// add adds a new repository to the server's list.
|
||||||
fn add(conf Config, url string, branch string, repo string, arch []string) ? {
|
fn add(conf Config, url string, branch string, repo string) ? {
|
||||||
res := add_repo(conf.address, conf.api_key, url, branch, repo, arch) ?
|
res := add_repo(conf.address, conf.api_key, url, branch, repo, []) ?
|
||||||
|
|
||||||
println(res.message)
|
println(res.message)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// 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> {
|
pub fn add_repo(address string, api_key string, url string, branch string, repo string, arch []string) ?Response<string> {
|
||||||
params := {
|
mut params := {
|
||||||
'url': url
|
'url': url
|
||||||
'branch': branch
|
'branch': branch
|
||||||
'repo': repo
|
'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) ?
|
data := send_request<string>(http.Method.post, address, '/api/repos', api_key, params) ?
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -57,7 +57,15 @@ fn (mut app App) post_repo() web.Result {
|
||||||
return app.json(http.Status.unauthorized, new_response('Unauthorized.'))
|
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()))
|
return app.json(http.Status.bad_request, new_response(err.msg()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue