Skip to content

Commit

Permalink
Fixing the webhook (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
Skarlso authored Jun 25, 2020
1 parent f072de7 commit 5519f27
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions handlers/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}

Expand All @@ -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())
Expand Down

0 comments on commit 5519f27

Please sign in to comment.