Dispatch passed arguments

This commit is contained in:
Quentin 2023-03-15 08:51:13 +01:00
parent 3fff73597f
commit 0baf1efabc
Signed by: quentin
GPG key ID: E9602264D639FF68
3 changed files with 19 additions and 4 deletions

7
example/albatros.json Normal file
View file

@ -0,0 +1,7 @@
{
"ref": "refs/heads/main",
"after": "3fff73597f8ca18ef04c0d9bf64132ba55aadcaa",
"repository": {
"clone_url": "https://git.deuxfleurs.fr/quentin/albatros.git"
}
}

16
main.go
View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"strings"
"net/http"
nomad "github.com/hashicorp/nomad/api"
//"code.gitea.io/sdk/gitea"
@ -77,14 +78,21 @@ func hook(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("Gitea notification: %+v\n", notification)
meta := map[string]string{
"REPO_URL": "https://git.deuxfleurs.fr/quentin/albatros.git",
"COMMIT": "9fc771827e94e89e28107a0a13ec8c11b6f740b8",
"BRANCH": "poc/nomad-ci",
"REPO_URL": notification.Repository.CloneUrl,
"COMMIT": notification.After,
// @FIXME: this code is not correct, this is a hack
"BRANCH": strings.ReplaceAll(notification.Ref, "refs/heads/", ""),
}
jobs := NomadClient.Jobs()
jobs.Dispatch("builder", meta, []byte{}, "test", &nomad.WriteOptions{})
dres, dmeta, err := jobs.Dispatch("builder", meta, []byte{}, "albatros", &nomad.WriteOptions{})
if err != nil {
http.Error(w, "Can't submit your job to Nomad", http.StatusInternalServerError)
}
log.Printf("Dispatch info: %+v\n", dmeta)
log.Printf("Job info: %+v\n", dres)
fmt.Println(notification.CompareUrl)
io.WriteString(w, "ok")