···
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/knotserver/config"
"tangled.sh/tangled.sh/core/knotserver/db"
"tangled.sh/tangled.sh/core/knotserver/git"
···
type PushOptions struct {
func (h *InternalHandle) PostReceiveHook(w http.ResponseWriter, r *http.Request) {
···
for _, option := range pushOptionsRaw {
if option == "skip-ci" || option == "ci-skip" {
pushOptions.skipCi = true
for _, line := range lines {
err := h.insertRefUpdate(line, gitUserDid, repoDid, repoName)
···
-
err = h.triggerPipeline(line, gitUserDid, repoDid, repoName, pushOptions)
l.Error("failed to trigger pipeline", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir)
func (h *InternalHandle) insertRefUpdate(line git.PostReceiveLine, gitUserDid, repoDid, repoName string) error {
···
return h.db.InsertEvent(event, h.n)
-
func (h *InternalHandle) triggerPipeline(line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {
···
var pipeline workflow.Pipeline
for _, e := range workflowDir {
···
wf, err := workflow.FromFile(e.Name, contents)
-
// TODO: log here, respond to client that is pushing
h.l.Error("failed to parse workflow", "err", err, "path", fpath)
···
-
// TODO: send the diagnostics back to the user here via stderr
cp := compiler.Compile(pipeline)
eventJson, err := json.Marshal(cp)
// do not run empty pipelines
···
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"tangled.sh/tangled.sh/core/api/tangled"
+
"tangled.sh/tangled.sh/core/hook"
"tangled.sh/tangled.sh/core/knotserver/config"
"tangled.sh/tangled.sh/core/knotserver/db"
"tangled.sh/tangled.sh/core/knotserver/git"
···
type PushOptions struct {
func (h *InternalHandle) PostReceiveHook(w http.ResponseWriter, r *http.Request) {
···
for _, option := range pushOptionsRaw {
if option == "skip-ci" || option == "ci-skip" {
pushOptions.skipCi = true
+
if option == "verbose-ci" || option == "ci-verbose" {
+
pushOptions.verboseCi = true
+
resp := hook.HookResponse{
+
Messages: make([]string, 0),
for _, line := range lines {
err := h.insertRefUpdate(line, gitUserDid, repoDid, repoName)
···
+
err = h.triggerPipeline(&resp.Messages, line, gitUserDid, repoDid, repoName, pushOptions)
l.Error("failed to trigger pipeline", "err", err, "line", line, "did", gitUserDid, "repo", gitRelativeDir)
func (h *InternalHandle) insertRefUpdate(line git.PostReceiveLine, gitUserDid, repoDid, repoName string) error {
···
return h.db.InsertEvent(event, h.n)
+
func (h *InternalHandle) triggerPipeline(clientMsgs *[]string, line git.PostReceiveLine, gitUserDid, repoDid, repoName string, pushOptions PushOptions) error {
···
+
pipelineParseErrors := []string{}
var pipeline workflow.Pipeline
for _, e := range workflowDir {
···
wf, err := workflow.FromFile(e.Name, contents)
h.l.Error("failed to parse workflow", "err", err, "path", fpath)
+
pipelineParseErrors = append(pipelineParseErrors, fmt.Sprintf("- at %s: %s\n", fpath, err))
···
cp := compiler.Compile(pipeline)
eventJson, err := json.Marshal(cp)
+
if pushOptions.verboseCi {
+
hasDiagnostics := false
+
if len(pipelineParseErrors) > 0 {
+
*clientMsgs = append(*clientMsgs, "error: failed to parse workflow(s):")
+
for _, error := range pipelineParseErrors {
+
*clientMsgs = append(*clientMsgs, error)
+
if len(compiler.Diagnostics.Errors) > 0 {
+
*clientMsgs = append(*clientMsgs, "error(s) on pipeline:")
+
for _, error := range compiler.Diagnostics.Errors {
+
*clientMsgs = append(*clientMsgs, fmt.Sprintf("- %s:", error))
+
if len(compiler.Diagnostics.Warnings) > 0 {
+
*clientMsgs = append(*clientMsgs, "warning(s) on pipeline:")
+
for _, warning := range compiler.Diagnostics.Warnings {
+
*clientMsgs = append(*clientMsgs, fmt.Sprintf("- at %s: %s: %s", warning.Path, warning.Type, warning.Reason))
+
*clientMsgs = append(*clientMsgs, "success: pipeline compiled with no diagnostics")
// do not run empty pipelines