From ae9b036cb574370bf28f2a5e3925c613a98ab2cb Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sun, 11 Feb 2024 23:07:14 -0500 Subject: [PATCH] fix: need to convert struct to a map to inject installation id --- api/webhook_manager.go | 14 +++++++++++--- go.mod | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/api/webhook_manager.go b/api/webhook_manager.go index 3a43eb6..7e6c025 100644 --- a/api/webhook_manager.go +++ b/api/webhook_manager.go @@ -2,10 +2,11 @@ package api import ( "bytes" - "code.gitea.io/gitea/modules/structs" + giteaTypes "code.gitea.io/gitea/modules/structs" "encoding/json" "git.lumeweb.com/LumeWeb/gitea-github-proxy/config" "git.lumeweb.com/LumeWeb/gitea-github-proxy/db/model" + "github.com/fatih/structs" "go.uber.org/zap" "gorm.io/gorm" "io" @@ -28,7 +29,7 @@ func NewWebhookManager(cfg *config.Config, db *gorm.DB, logger *zap.Logger) *Web return &WebhookManager{config: cfg, db: db, logger: logger} } -func (whm *WebhookManager) HandlePullRequest(request *structs.PullRequestPayload, r *http.Request) { +func (whm *WebhookManager) HandlePullRequest(request *giteaTypes.PullRequestPayload, r *http.Request) { ghEvent := convertPullRequestEvent(request) githubAction := translatePrAction(request.Action) r.Header.Set("X-GitHub-Event", githubAction) @@ -44,7 +45,14 @@ func (whm *WebhookManager) sendWebhooks(request interface{}, r *http.Request) { } for _, app := range apps { go func(app model.Apps) { - payloadBytes, err := json.Marshal(request) + + rawMap := structs.New(request).Map() + + rawMap["installation"] = struct { + ID uint `json:"id"` + }{ID: app.ID} + + payloadBytes, err := json.Marshal(rawMap) if err != nil { whm.logger.Error("Failed to marshal payload", zap.Error(err)) return diff --git a/go.mod b/go.mod index 9bb0b28..4859037 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,6 @@ require ( github.com/google/go-github/v59 v59.0.0 github.com/gorilla/mux v1.8.1 github.com/iancoleman/strcase v0.3.0 - github.com/mitchellh/mapstructure v1.5.0 github.com/spf13/viper v1.18.2 go.uber.org/fx v1.20.1 go.uber.org/zap v1.26.0 @@ -32,6 +31,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-sqlite3 v1.14.17 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect