diff --git a/handlers/hook.go b/handlers/hook.go index 61e7a20d..6307d933 100644 --- a/handlers/hook.go +++ b/handlers/hook.go @@ -71,6 +71,9 @@ func parse(secret []byte, req *http.Request) (Hook, error) { } if h.Event != "push" { + if h.Event == "ping" { + return Hook{Event: "ping"}, nil + } return Hook{}, errors.New("invalid event") } @@ -111,13 +114,15 @@ func GitWebHook(c echo.Context) error { h, err := parse(secret, c.Request()) c.Request().Header.Set("Content-type", "application/json") - if err != nil { return c.String(http.StatusBadRequest, err.Error()) } + if h.Event == "ping" { + return c.NoContent(http.StatusOK) + } - p := new(Payload) - if err := json.Unmarshal(h.Payload, p); err != nil { + p := Payload{} + if err := json.Unmarshal(h.Payload, &p); err != nil { return c.String(http.StatusBadRequest, "error in unmarshalling json payload") } @@ -128,6 +133,9 @@ func GitWebHook(c echo.Context) error { break } } + if foundPipe == nil { + return c.String(http.StatusInternalServerError, "pipeline not found") + } err = pipeline.UpdateRepository(foundPipe) if err != nil { message := fmt.Sprintln("failed to build pipeline: ", err.Error())