diff --git a/Deps b/Deps index cc87ab7..eecb84d 100644 --- a/Deps +++ b/Deps @@ -109,7 +109,8 @@ }, { "ImportPath": "github.com/rafecolton/vauth", - "Rev": "3c5da807bc47903e09eba6d4efef3cd9ad916851" + "Comment": "v0.1.1", + "Rev": "b89e34040982b43a38140aa246583c54cc75542f" }, { "ImportPath": "github.com/wsxiaoys/terminal/color", diff --git a/server/webhook/github.go b/server/webhook/github.go index 03d547d..2a721f0 100644 --- a/server/webhook/github.go +++ b/server/webhook/github.go @@ -1,7 +1,9 @@ package webhook import ( + "bytes" "encoding/json" + "fmt" "io/ioutil" "net/http" @@ -35,18 +37,21 @@ func Github(w http.ResponseWriter, req *http.Request) (int, string) { event := req.Header.Get("X-Github-Event") if !githubSupportedEvents[event] { logger.Errorf("Github event type %s is not supported.", event) - return 400, "400 bad request" + return http.StatusBadRequest, fmt.Sprintf("%d bad request", http.StatusBadRequest) } body, err := ioutil.ReadAll(req.Body) defer req.Body.Close() + if err != nil { logger.Error(err) - return 400, "400 bad request" + return http.StatusBadRequest, fmt.Sprintf("%d bad request", http.StatusBadRequest) } + + decoder := json.NewDecoder(bytes.NewReader(body)) var payload = &githubPushPayload{} - if err = json.Unmarshal([]byte(body), payload); err != nil { + if err := decoder.Decode(payload); err != nil { logger.Error(err) - return 400, "400 bad request" + return http.StatusBadRequest, fmt.Sprintf("%d bad request", http.StatusBadRequest) } spec := &job.Spec{