Skip to content

Commit

Permalink
handle both content types of github webhooks
Browse files Browse the repository at this point in the history
  • Loading branch information
piranha committed Jun 17, 2020
1 parent 9666e03 commit 6bdea0a
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions webhooker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// (c) 2013 Alexander Solovyov under terms of ISC License
// (c) 2013-2020 Alexander Solovyov under terms of ISC License

package main

Expand All @@ -17,7 +17,7 @@ import (

/// Globals

var Version = "0.2"
var Version = "0.3"

var opts struct {
Interface string `short:"i" long:"interface" default:"127.0.0.1" description:"ip to listen on"`
Expand Down Expand Up @@ -166,8 +166,16 @@ func (c Config) ExecutePayload(data Payload) error {
}

func (c Config) HandleRequest(w http.ResponseWriter, r *http.Request) {
ctype := r.Header.Get("Content-type")

data := new(GithubPayload)
err := json.Unmarshal([]byte(r.PostFormValue("payload")), data)
var err error
if ctype == "application/json" {
decoder := json.NewDecoder(r.Body)
err = decoder.Decode(&data)
} else {
err = json.Unmarshal([]byte(r.PostFormValue("payload")), data)
}
if err != nil {
log.Println(err)
w.WriteHeader(http.StatusInternalServerError)
Expand Down

0 comments on commit 6bdea0a

Please sign in to comment.