forked from vieter-v/vieter
Compare commits
No commits in common. "78310fa1e425652fb0f2f2e29865a6f2b9310cf0" and "b31b4cbd7a9fc1b64061c253e4260f66d56e0430" have entirely different histories.
78310fa1e4
...
b31b4cbd7a
|
|
@ -3,7 +3,9 @@ module build
|
|||
import docker
|
||||
import encoding.base64
|
||||
import time
|
||||
import net.http
|
||||
import git
|
||||
import json
|
||||
|
||||
const container_build_dir = '/build'
|
||||
|
||||
|
|
@ -61,7 +63,11 @@ fn create_build_image() ?string {
|
|||
|
||||
fn build(conf Config) ? {
|
||||
// We get the repos list from the Vieter instance
|
||||
repos := git.get_repos(conf.address, conf.api_key) ?
|
||||
mut req := http.new_request(http.Method.get, '$conf.address/api/repos', '') ?
|
||||
req.add_custom_header('X-Api-Key', conf.api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
repos := json.decode([]git.GitRepo, res.text) ?
|
||||
|
||||
// No point in doing work if there's no repos present
|
||||
if repos.len == 0 {
|
||||
|
|
@ -71,7 +77,7 @@ fn build(conf Config) ? {
|
|||
// First, we create a base image which has updated repos n stuff
|
||||
image_id := create_build_image() ?
|
||||
|
||||
for _, repo in repos {
|
||||
for repo in repos {
|
||||
// TODO what to do with PKGBUILDs that build multiple packages?
|
||||
commands := [
|
||||
'git clone --single-branch --depth 1 --branch $repo.branch $repo.url repo',
|
||||
|
|
|
|||
|
|
@ -2,6 +2,9 @@ module git
|
|||
|
||||
import cli
|
||||
import env
|
||||
import net.http
|
||||
import json
|
||||
import response
|
||||
|
||||
struct Config {
|
||||
address string [required]
|
||||
|
|
@ -52,8 +55,18 @@ pub fn cmd() cli.Command {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_repos(conf Config) ?map[string]GitRepo {
|
||||
mut req := http.new_request(http.Method.get, '$conf.address/api/repos', '') ?
|
||||
req.add_custom_header('X-API-Key', conf.api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
data := json.decode(response.Response<map[string]GitRepo>, res.text) ?
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
fn list(conf Config) ? {
|
||||
repos := get_repos(conf.address, conf.api_key) ?
|
||||
repos := get_repos(conf) ?
|
||||
|
||||
for id, details in repos {
|
||||
println('${id[..8]}\t$details.url\t$details.branch\t$details.arch')
|
||||
|
|
@ -61,13 +74,17 @@ fn list(conf Config) ? {
|
|||
}
|
||||
|
||||
fn add(conf Config, url string, branch string, arch []string) ? {
|
||||
res := add_repo(conf.address, conf.api_key, url, branch, arch) ?
|
||||
mut req := http.new_request(http.Method.post, '$conf.address/api/repos?url=$url&branch=$branch&arch=${arch.join(',')}',
|
||||
'') ?
|
||||
req.add_custom_header('X-API-Key', conf.api_key) ?
|
||||
|
||||
println(res.message)
|
||||
res := req.do() ?
|
||||
|
||||
println(res.text)
|
||||
}
|
||||
|
||||
fn remove(conf Config, id_prefix string) ? {
|
||||
repos := get_repos(conf.address, conf.api_key) ?
|
||||
repos := get_repos(conf) ?
|
||||
|
||||
mut to_remove := []string{}
|
||||
|
||||
|
|
@ -87,7 +104,11 @@ fn remove(conf Config, id_prefix string) ? {
|
|||
exit(1)
|
||||
}
|
||||
|
||||
res := remove_repo(conf.address, conf.api_key, to_remove[0]) ?
|
||||
mut req := http.new_request(http.Method.delete, '$conf.address/api/repos/${to_remove[0]}',
|
||||
'') ?
|
||||
req.add_custom_header('X-API-Key', conf.api_key) ?
|
||||
|
||||
println(res.message)
|
||||
res := req.do() ?
|
||||
|
||||
println(res.text)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
module git
|
||||
|
||||
import json
|
||||
import response { Response }
|
||||
import net.http
|
||||
|
||||
// get_repos returns the current list of repos.
|
||||
pub fn get_repos(address string, api_key string) ?map[string]GitRepo {
|
||||
mut req := http.new_request(http.Method.get, '$address/api/repos', '') ?
|
||||
req.add_custom_header('X-API-Key', api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
data := json.decode(Response<map[string]GitRepo>, res.text) ?
|
||||
|
||||
return data.data
|
||||
}
|
||||
|
||||
// add_repo adds a new repo to the server.
|
||||
pub fn add_repo(address string, api_key string, url string, branch string, arch []string) ?Response<string> {
|
||||
mut req := http.new_request(http.Method.post, '$address/api/repos?url=$url&branch=$branch&arch=${arch.join(',')}',
|
||||
'') ?
|
||||
req.add_custom_header('X-API-Key', api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
data := json.decode(Response<string>, res.text) ?
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// remove_repo removes the repo with the given ID from the server.
|
||||
pub fn remove_repo(address string, api_key string, id string) ?Response<string> {
|
||||
mut req := http.new_request(http.Method.delete, '$address/api/repos/$id', '') ?
|
||||
req.add_custom_header('X-API-Key', api_key) ?
|
||||
|
||||
res := req.do() ?
|
||||
data := json.decode(Response<string>, res.text) ?
|
||||
|
||||
return data
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
module response
|
||||
|
||||
pub struct Response<T> {
|
||||
pub:
|
||||
message string
|
||||
data T
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue