Skip to content

Commit

Permalink
Use json event format
Browse files Browse the repository at this point in the history
  • Loading branch information
pcarranza committed Sep 18, 2018
1 parent a9840ff commit fb9a1f8
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"net/http"

"github.com/onrik/logrus/filename"
Expand All @@ -21,22 +22,20 @@ func main() {
}

func handleGithub(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
logrus.Debugf("failed to parse form on request %s: %#v", r, err)
http.Error(w, fmt.Sprintf("bad request: %s", err), http.StatusBadRequest)
return
}
// This requires registering the webhooks using json format and only receive
// pull request events

payload := r.FormValue("payload")
if payload == "" {
logrus.Debugf("no payload in form %#v", r.Form)
http.Error(w, "no payload in form", http.StatusBadRequest)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
logrus.Errorf("failed to read body: %s", err)
http.Error(w, fmt.Sprintf("bad request: %s", err), http.StatusBadRequest)
return
}
defer r.Body.Close()

w.WriteHeader(http.StatusAccepted)

logrus.Println("received Webhook payload: %s", payload)
logrus.Infof("received Webhook payload: %s", string(body))
}

func setupLogger() {
Expand Down

0 comments on commit fb9a1f8

Please sign in to comment.