From 1db814b5d33ea1705233c0e6f00f2dd75b743ceb2ebd453b3ab9e07468a9c65d Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Sat, 24 Aug 2024 17:20:46 +0200 Subject: [PATCH] . --- bots-common/request_create.go | 2 +- bots-common/request_fork.go | 7 +++++++ gitea-events-rabbitmq-publisher/main.go | 25 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 bots-common/request_fork.go diff --git a/bots-common/request_create.go b/bots-common/request_create.go index 7ccb173..01f2f71 100644 --- a/bots-common/request_create.go +++ b/bots-common/request_create.go @@ -1,6 +1,6 @@ package common -type CreateWebhook struct { +type CreateWebhookEvent struct { Sha string Ref string // name of tag/branch Ref_type string // tag, branch diff --git a/bots-common/request_fork.go b/bots-common/request_fork.go new file mode 100644 index 0000000..1f6e44e --- /dev/null +++ b/bots-common/request_fork.go @@ -0,0 +1,7 @@ +package common + +type ForkWebhookEvent struct { + Forkee Repository + Repository + Sender User +} diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index 3ec6549..cf637f8 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -91,14 +91,35 @@ func main() { // repo := common.Repository{} switch reqType { case "create", "delete": - create := common.CreateWebhook{} + create := common.CreateWebhookEvent{} if err = json.Unmarshal(data, &create); err != nil { res.WriteHeader(http.StatusBadRequest) if DebugMode { dumpUnhandledData(reqType, data) } + return } // repo = create.Repository + case "fork": + fork := common.ForkWebhookEvent{} + if err = json.Unmarshal(data, &fork); err != nil { + res.WriteHeader(http.StatusBadRequest) + if DebugMode { + dumpUnhandledData(reqType, data) + } + return + } +// repo = fork.Forkee + case "push": + push := common.PushRequest{} + if err = json.Unmarshal(data, &push); err != nil { + res.WriteHeader(http.StatusBadRequest) + if DebugMode { + dumpUnhandledData(reqType, data) + } + return + } +// repo = push.Repository } // err = PublishMessage(repo.Owner.Username, reqType, data) @@ -107,7 +128,7 @@ func main() { connectionId++ /* - err = PublishMessage(reqType, req.PathValue("Org"), data) + err = PublishMessage(repo.Name, reqType, data) if err != nil { errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) res.Header().Add("Content-Type", "plain/text")