mirror of https://git.jolheiser.com/ugit.git
feat: ugit-uci
Signed-off-by: jolheiser <git@jolheiser.com>
parent
79c3e14082
commit
285640256e
|
@ -0,0 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
||||
func main() {
|
||||
repoDir, ok := os.LookupEnv("UGIT_REPODIR")
|
||||
if !ok {
|
||||
panic("UGIT_REPODIR not set")
|
||||
}
|
||||
|
||||
urlFlag := flag.String("url", "http://localhost:3448", "URL for UCI")
|
||||
flag.StringVar(urlFlag, "u", *urlFlag, "--url")
|
||||
repoDirFlag := flag.String("repo-dir", "", "Repo dir (including .git)")
|
||||
flag.StringVar(repoDirFlag, "rd", *repoDirFlag, "--repo-dir")
|
||||
manifestFlag := flag.String("manifest", ".uci.jsonnet", "Path to manifest in repo")
|
||||
flag.StringVar(manifestFlag, "m", *manifestFlag, "--manifest")
|
||||
flag.Parse()
|
||||
|
||||
if *repoDirFlag != "" {
|
||||
repoDir = *repoDirFlag
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(repoDir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tree, err := repo.Worktree()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fi, err := tree.Filesystem.Open(*manifestFlag)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer fi.Close()
|
||||
|
||||
data, err := io.ReadAll(fi)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
resp, err := http.Post(*urlFlag, "applicaiton/jsonnet", bytes.NewReader(data))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
panic(fmt.Sprintf("non-ok response: %s", resp.Status))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue