fix: need to convert struct to a map to inject installation id
This commit is contained in:
parent
d5ac5e4b3c
commit
ae9b036cb5
|
@ -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
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
Loading…
Reference in New Issue