Skip to content

Commit

Permalink
Merge pull request #146 from rafecolton/fix-bug-with-failure-to-retri…
Browse files Browse the repository at this point in the history
…eve-request-body-on-github-webhook

Fix bug with failure to retrieve request body on github webhook
  • Loading branch information
Rafe Colton committed Oct 30, 2014
2 parents 6b14aeb + 6d386c3 commit 23a6191
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Deps
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
},
{
"ImportPath": "github.com/rafecolton/vauth",
"Rev": "3c5da807bc47903e09eba6d4efef3cd9ad916851"
"Comment": "v0.1.1",
"Rev": "b89e34040982b43a38140aa246583c54cc75542f"
},
{
"ImportPath": "github.com/wsxiaoys/terminal/color",
Expand Down
13 changes: 9 additions & 4 deletions server/webhook/github.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package webhook

import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 23a6191

Please sign in to comment.