Builder now uses new Git repos API

main^2
Jef Roosens 2022-04-07 12:10:37 +02:00
parent fc1d4480dc
commit 78310fa1e4
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 8 additions and 11 deletions

View File

@ -3,9 +3,7 @@ module build
import docker
import encoding.base64
import time
import net.http
import git
import json
const container_build_dir = '/build'
@ -63,11 +61,7 @@ fn create_build_image() ?string {
fn build(conf Config) ? {
// We get the repos list from the Vieter instance
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) ?
repos := git.get_repos(conf.address, conf.api_key) ?
// No point in doing work if there's no repos present
if repos.len == 0 {
@ -77,7 +71,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',

View File

@ -4,7 +4,8 @@ import json
import response { Response }
import net.http
fn get_repos(address string, api_key string) ?map[string]GitRepo {
// 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) ?
@ -14,7 +15,8 @@ fn get_repos(address string, api_key string) ?map[string]GitRepo {
return data.data
}
fn add_repo(address string, api_key string, url string, branch string, arch []string) ?Response<string> {
// 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) ?
@ -25,7 +27,8 @@ fn add_repo(address string, api_key string, url string, branch string, arch []st
return data
}
fn remove_repo(address string, api_key string, id string) ?Response<string> {
// 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) ?