diff --git a/src/git/cli.v b/src/git/cli.v index 3a1f2e3..53527d5 100644 --- a/src/git/cli.v +++ b/src/git/cli.v @@ -2,7 +2,6 @@ module git import cli import env -import cron.expression { parse_expression } struct Config { address string [required] @@ -27,14 +26,14 @@ pub fn cmd() cli.Command { }, cli.Command{ name: 'add' - required_args: 3 - usage: 'url branch repo' + required_args: 4 + usage: 'url branch repo arch...' 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]) ? + add(conf, cmd.args[0], cmd.args[1], cmd.args[2], cmd.args[3..]) ? } }, cli.Command{ @@ -49,18 +48,6 @@ pub fn cmd() cli.Command { remove(conf, cmd.args[0]) ? } }, - cli.Command{ - name: 'info' - required_args: 1 - usage: 'id' - description: 'Show detailed information for the repo matching the ID prefix.' - execute: fn (cmd cli.Command) ? { - config_file := cmd.flags.get_string('config-file') ? - conf := env.load(config_file) ? - - info(conf, cmd.args[0]) ? - } - }, cli.Command{ name: 'edit' required_args: 1 @@ -87,11 +74,6 @@ pub fn cmd() cli.Command { description: 'Comma-separated list of architectures to build on.' flag: cli.FlagType.string }, - cli.Flag{ - name: 'schedule' - description: 'Cron schedule for repository.' - flag: cli.FlagType.string - }, ] execute: fn (cmd cli.Command) ? { config_file := cmd.flags.get_string('config-file') ? @@ -114,16 +96,16 @@ pub fn cmd() cli.Command { } } -// get_repo_by_prefix tries to find the repo with the given prefix in its +// get_repo_id_by_prefix tries to find the repo with the given prefix in its // ID. If multiple or none are found, an error is raised. -fn get_repo_by_prefix(conf Config, id_prefix string) ?(string, GitRepo) { +fn get_repo_id_by_prefix(conf Config, id_prefix string) ?string { repos := get_repos(conf.address, conf.api_key) ? - mut res := map[string]GitRepo{} + mut res := []string{} - for id, repo in repos { + for id, _ in repos { if id.starts_with(id_prefix) { - res[id] = repo + res << id } } @@ -135,7 +117,7 @@ fn get_repo_by_prefix(conf Config, id_prefix string) ?(string, GitRepo) { return error('Multiple repos found for given prefix.') } - return res.keys()[0], res[res.keys()[0]] + return res[0] } // list prints out a list of all repositories. @@ -143,20 +125,20 @@ fn list(conf Config) ? { repos := get_repos(conf.address, conf.api_key) ? for id, details in repos { - println('${id[..8]}\t$details.url\t$details.branch\t$details.repo') + println('${id[..8]}\t$details.url\t$details.branch\t$details.repo\t$details.arch') } } // add adds a new repository to the server's list. -fn add(conf Config, url string, branch string, repo string) ? { - res := add_repo(conf.address, conf.api_key, url, branch, repo, []) ? +fn add(conf Config, url string, branch string, repo string, arch []string) ? { + res := add_repo(conf.address, conf.api_key, url, branch, repo, arch) ? println(res.message) } // remove removes a repository from the server's list. fn remove(conf Config, id_prefix string) ? { - id, _ := get_repo_by_prefix(conf, id_prefix) ? + id := get_repo_id_by_prefix(conf, id_prefix) ? res := remove_repo(conf.address, conf.api_key, id) ? println(res.message) @@ -164,28 +146,8 @@ fn remove(conf Config, id_prefix string) ? { // patch patches a given repository with the provided params. fn patch(conf Config, id_prefix string, params map[string]string) ? { - // We check the cron expression first because it's useless to send an - // invalid one to the server. - if 'schedule' in params { - parse_expression(params['schedule']) or { - return error('Invalid cron expression: $err.msg()') - } - } - - id, _ := get_repo_by_prefix(conf, id_prefix) ? + id := get_repo_id_by_prefix(conf, id_prefix) ? res := patch_repo(conf.address, conf.api_key, id, params) ? println(res.message) } - -// info shows detailed information for a given repo. -fn info(conf Config, id_prefix string) ? { - id, repo := get_repo_by_prefix(conf, id_prefix) ? - - println('id: $id') - - $for field in GitRepo.fields { - val := repo.$(field.name) - println('$field.name: $val') - } -} diff --git a/src/git/client.v b/src/git/client.v index 0ed19b5..a43c9ca 100644 --- a/src/git/client.v +++ b/src/git/client.v @@ -35,16 +35,12 @@ 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 { - mut params := { + 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 c136d98..0cba17c 100644 --- a/src/server/git.v +++ b/src/server/git.v @@ -57,15 +57,7 @@ fn (mut app App) post_repo() web.Result { return app.json(http.Status.unauthorized, new_response('Unauthorized.')) } - 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 { + new_repo := git.repo_from_params(app.query) or { return app.json(http.Status.bad_request, new_response(err.msg())) }