From b1ac39e2347406600bfed8929b63d89190fffebc Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Sun, 1 May 2022 12:44:54 +0200 Subject: [PATCH] feat: made arch param optional when adding Git repo --- src/git/cli.v | 10 +++++----- src/git/client.v | 8 ++++++-- src/server/git.v | 10 +++++++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/git/cli.v b/src/git/cli.v index 53527d52..f7f125c9 100644 --- a/src/git/cli.v +++ b/src/git/cli.v @@ -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_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) } diff --git a/src/git/client.v b/src/git/client.v index a43c9ca0..0ed19b57 100644 --- a/src/git/client.v +++ b/src/git/client.v @@ -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 { - params := { + mut params := { 'url': url 'branch': branch 'repo': repo - 'arch': arch.join(',') } + + if arch.len > 0 { + params['arch'] = arch.join(',') + } + data := send_request(http.Method.post, address, '/api/repos', api_key, params) ? return data diff --git a/src/server/git.v b/src/server/git.v index 0cba17cb..c136d986 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -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())) }