func OnReceiveRequest(r *http.Request, secretToken string) (string, *github.Repository, *mevt.MessageEventContent, *util.JSONResponse) {
	eventType := r.Header.Get("X-GitHub-Event")
	signatureSHA1 := r.Header.Get("X-Hub-Signature")
	content, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.WithError(err).Print("Failed to read Github webhook body")
		resErr := util.MessageResponse(400, "Failed to parse body")
		return "", nil, nil, &resErr
	}
	if secretToken != "" {
		sigHex := strings.Split(signatureSHA1, "=")[1]
		var sigBytes []byte
		sigBytes, err = hex.DecodeString(sigHex)
		if err != nil {
			log.WithError(err).WithField("X-Hub-Signature", sigHex).Print(
				"Failed to decode signature as hex.")
			resErr := util.MessageResponse(400, "Failed to decode signature")
			return "", nil, nil, &resErr
		}
		if !checkMAC([]byte(content), sigBytes, []byte(secretToken)) {
			log.WithFields(log.Fields{
				"X-Hub-Signature": signatureSHA1,
			}).Print("Received Github event which failed MAC check.")
			resErr := util.MessageResponse(403, "Bad signature")
			return "", nil, nil, &resErr
		}
	}
	log.WithFields(log.Fields{
		"event_type": eventType,
		"signature":  signatureSHA1,
	}).Print("Received Github event")
	if eventType == "ping" {
		res := util.MessageResponse(200, "pong")
		return "", nil, nil, &res
	}
	htmlStr, repo, refinedType, err := parseGithubEvent(eventType, content)
	if err != nil {
		log.WithError(err).Print("Failed to parse github event")
		resErr := util.MessageResponse(500, "Failed to parse github event")
		return "", nil, nil, &resErr
	}
	msg := utils.StrippedHTMLMessage(mevt.MsgNotice, htmlStr)
	return refinedType, repo, &msg, nil
}
OnReceiveRequest processes incoming github webhook requests and returns a
matrix message to send, along with parsed repo information.
The secretToken, if supplied, will be used to verify the request is from
Github. If it isn't, an error is returned.
package webhook
import (
	"crypto/hmac"
	"crypto/sha1"
	"encoding/hex"
	"encoding/json"
	"fmt"
	"html"
	"io/ioutil"
	"net/http"
	"strings"
	"github.com/google/go-github/github"
	"github.com/matrix-org/go-neb/services/utils"
	"github.com/matrix-org/util"
	log "github.com/sirupsen/logrus"
	mevt "maunium.net/go/mautrix/event"
)