From 7f3198f825c3e5bd66488b514a72856034d377b2 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Tue, 10 Mar 2020 14:41:11 -0400 Subject: [PATCH] feat(github-gatewa): added headers to event payload (#536) --- gateways/server/github/start.go | 15 ++++++++++++++- pkg/apis/events/event-data.go | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gateways/server/github/start.go b/gateways/server/github/start.go index 6bc3ca48c7..e8c8c45938 100644 --- a/gateways/server/github/start.go +++ b/gateways/server/github/start.go @@ -20,6 +20,7 @@ import ( "context" "encoding/json" "github.com/argoproj/argo-events/gateways/server" + "github.com/argoproj/argo-events/pkg/apis/events" "net/http" "net/url" "time" @@ -105,8 +106,20 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ return } + event := &events.GithubEventData{ + Headers: request.Header, + Body: (*json.RawMessage)(&body), + } + + eventBody, err := json.Marshal(event) + if err != nil { + logger.Info("failed to marshal event") + common.SendErrorResponse(writer, "invalid event") + return + } + logger.Infoln("dispatching event on route's data channel") - route.DataCh <- body + route.DataCh <- eventBody logger.Info("request successfully processed") common.SendSuccessResponse(writer, "success") diff --git a/pkg/apis/events/event-data.go b/pkg/apis/events/event-data.go index eacc31d6a4..f493cbbdf1 100644 --- a/pkg/apis/events/event-data.go +++ b/pkg/apis/events/event-data.go @@ -121,8 +121,10 @@ type PubSubEventData struct { // GithubEventData represents the event data generated by the GitHub gateway. type GithubEventData struct { + // Headers from the Gitlab http request. + Headers http.Header `json:"headers"` // Body represents the message body - Body []byte `json:"body"` + Body *json.RawMessage `json:"body"` } // GitLabEventData represents the event data generated by the GitLab gateway.