eclipse/cmd/hub/hub.go

71 lines
1.2 KiB
Go
Raw Normal View History

2024-01-11 00:13:14 +00:00
// Copyright (C) 2024 Umorpha Systems
// SPDX-License-Identifier: AGPL-3.0-or-later
package main
import (
"fmt"
"io"
"os"
2024-01-11 20:36:03 +00:00
"errors"
2024-01-11 17:59:26 +00:00
"os/exec"
"git.mothstuff.lol/lukeshu/eclipse/lib"
2024-01-11 00:13:14 +00:00
"sigs.k8s.io/yaml"
)
type GitTrigger struct {
RepoURL string `json:"repo_url"`
Rev string `json:"rev"`
}
2024-01-11 17:59:26 +00:00
func FetchRepo(cacheDir, url string) error {
2024-01-11 20:36:03 +00:00
cmd := exec.Command("git",
"--namespace="+lib.URLToID(url),
"fetch",
2024-01-11 17:59:26 +00:00
"--no-write-fetch-head",
"--no-recurse-submodules",
"--no-tags",
"--prune",
"--",
2024-01-11 20:36:03 +00:00
url, "*:*")
2024-01-11 17:59:26 +00:00
cmd.Dir = cacheDir
if err := cmd.Run(); err != nil {
2024-01-11 20:36:03 +00:00
var eErr *exec.ExitError
if errors.As(err, &eErr) {
err = fmt.Errorf("%w: %s", err, eErr.Stderr)
}
2024-01-11 17:59:26 +00:00
return err
}
return nil
}
2024-01-11 00:13:14 +00:00
func Resolve(trigger GitTrigger) (string, error) {
return "", nil
}
func mainWithErr() error {
cfgBytes, err := io.ReadAll(os.Stdin)
if err != nil {
return err
}
var cfgObj GitTrigger
if err := yaml.UnmarshalStrict(cfgBytes, &cfgObj); err != nil {
return err
}
out, err := Resolve(cfgObj)
if err != nil {
return err
}
fmt.Println(out)
return nil
}
func main() {
if err := mainWithErr(); err != nil {
fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err)
os.Exit(1)
}
}