Removed old git code; ran format
parent
88b32f376f
commit
0a6c0b4c05
12
src/db/git.v
12
src/db/git.v
|
|
@ -29,12 +29,12 @@ pub mut:
|
|||
|
||||
pub fn (gr &GitRepo) str() string {
|
||||
mut parts := [
|
||||
"id: $gr.id",
|
||||
"url: $gr.url",
|
||||
"branch: $gr.branch",
|
||||
"repo: $gr.repo",
|
||||
"schedule: $gr.schedule",
|
||||
"arch: ${gr.arch.map(it.value).join(', ')}"
|
||||
'id: $gr.id',
|
||||
'url: $gr.url',
|
||||
'branch: $gr.branch',
|
||||
'repo: $gr.repo',
|
||||
'schedule: $gr.schedule',
|
||||
'arch: ${gr.arch.map(it.value).join(', ')}',
|
||||
]
|
||||
str := parts.join('\n')
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ module git
|
|||
import cli
|
||||
import env
|
||||
import cron.expression { parse_expression }
|
||||
import db { GitRepo, GitRepoArch }
|
||||
import db
|
||||
|
||||
struct Config {
|
||||
address string [required]
|
||||
|
|
@ -123,7 +123,7 @@ fn list(conf Config) ? {
|
|||
repos := get_repos(conf.address, conf.api_key) ?
|
||||
|
||||
for repo in repos {
|
||||
println('${repo.id}\t$repo.url\t$repo.branch\t$repo.repo')
|
||||
println('$repo.id\t$repo.url\t$repo.branch\t$repo.repo')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,8 @@ fn send_request<T>(method http.Method, address string, url string, api_key strin
|
|||
|
||||
// get_repos returns the current list of repos.
|
||||
pub fn get_repos(address string, api_key string) ?[]db.GitRepo {
|
||||
data := send_request<[]db.GitRepo>(http.Method.get, address, '/api/repos',
|
||||
api_key, {}) ?
|
||||
data := send_request<[]db.GitRepo>(http.Method.get, address, '/api/repos', api_key,
|
||||
{}) ?
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
module git
|
||||
|
||||
/* import os */
|
||||
/* import json */
|
||||
|
||||
/* pub struct GitRepo { */
|
||||
/* pub mut: */
|
||||
/* // URL of the Git repository */
|
||||
/* url string */
|
||||
/* // Branch of the Git repository to use */
|
||||
/* branch string */
|
||||
/* // On which architectures the package is allowed to be built. In reality, */
|
||||
/* // this controls which builders will periodically build the image. */
|
||||
/* arch []string */
|
||||
/* // Which repo the builder should publish packages to */
|
||||
/* repo string */
|
||||
/* // Cron schedule describing how frequently to build the repo. */
|
||||
/* schedule string [optional] */
|
||||
/* } */
|
||||
|
||||
/* // patch_from_params patches a GitRepo from a map[string]string, usually */
|
||||
/* // provided from a web.App's params */
|
||||
/* pub fn (mut r GitRepo) patch_from_params(params map[string]string) { */
|
||||
/* $for field in GitRepo.fields { */
|
||||
/* if field.name in params { */
|
||||
/* $if field.typ is string { */
|
||||
/* r.$(field.name) = params[field.name] */
|
||||
/* // This specific type check is needed for the compiler to ensure */
|
||||
/* // our types are correct */
|
||||
/* } $else $if field.typ is []string { */
|
||||
/* r.$(field.name) = params[field.name].split(',') */
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
/* // read_repos reads the provided path & parses it into a map of GitRepo's. */
|
||||
/* pub fn read_repos(path string) ?map[string]GitRepo { */
|
||||
/* if !os.exists(path) { */
|
||||
/* mut f := os.create(path) ? */
|
||||
|
||||
/* defer { */
|
||||
/* f.close() */
|
||||
/* } */
|
||||
|
||||
/* f.write_string('{}') ? */
|
||||
|
||||
/* return {} */
|
||||
/* } */
|
||||
|
||||
/* content := os.read_file(path) ? */
|
||||
/* res := json.decode(map[string]GitRepo, content) ? */
|
||||
|
||||
/* return res */
|
||||
/* } */
|
||||
|
||||
/* // write_repos writes a map of GitRepo's back to disk given the provided path. */
|
||||
/* pub fn write_repos(path string, repos &map[string]GitRepo) ? { */
|
||||
/* mut f := os.create(path) ? */
|
||||
|
||||
/* defer { */
|
||||
/* f.close() */
|
||||
/* } */
|
||||
|
||||
/* value := json.encode(repos) */
|
||||
/* f.write_string(value) ? */
|
||||
/* } */
|
||||
|
||||
/* // repo_from_params creates a GitRepo from a map[string]string, usually */
|
||||
/* // provided from a web.App's params */
|
||||
/* pub fn repo_from_params(params map[string]string) ?GitRepo { */
|
||||
/* mut repo := GitRepo{} */
|
||||
|
||||
/* // If we're creating a new GitRepo, we want all fields to be present before */
|
||||
/* // "patching". */
|
||||
/* $for field in GitRepo.fields { */
|
||||
/* if field.name !in params && !field.attrs.contains('optional') { */
|
||||
/* return error('Missing parameter: ${field.name}.') */
|
||||
/* } */
|
||||
/* } */
|
||||
/* repo.patch_from_params(params) */
|
||||
|
||||
/* return repo */
|
||||
/* } */
|
||||
Reference in New Issue