From ff877cc987ab3c77915c56327f9c4cdaf6358f66a15c69e7c539e897ccc384ea Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Mon, 26 Aug 2024 13:56:33 +0200 Subject: [PATCH] . --- gitea-events-rabbitmq-publisher/main.go | 38 ++++++++++++------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index 67a60aa..8c4d703 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -292,7 +292,7 @@ func main() { connectToRabbitMQ() - http.HandleFunc("POST /test", func(res http.ResponseWriter, req *http.Request) { + http.HandleFunc("POST /rabbitmq-forwarder", func(res http.ResponseWriter, req *http.Request) { if len(req.Header.Get("Content-Type")) == 0 || req.Header["Content-Type"][0] != "application/json" || req.Method != "POST" { @@ -337,31 +337,29 @@ func main() { if DebugMode { dumpUnhandledData(reqType, data) } - // return + return } - // err = PublishMessage(repo.Owner.Username, reqType, data) - // write to file for review - id++ - os.WriteFile("test_data."+fmt.Sprint(id), data, 0644) - if org != nil { - log.Println(id, org.Username, reqType, extraAction) + if org == nil { + res.WriteHeader(http.StatusBadRequest) + log.Printf("no `org` for message... type: %s", reqType) + if DebugMode { + dumpUnhandledData(reqType, data) + } } - /* - err = PublishMessage(org.Name, reqType, extraAction, data) - if err != nil { - errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) - res.Header().Add("Content-Type", "plain/text") - res.Write([]byte(errorStr)) - res.WriteHeader(http.StatusBadRequest) + err = PublishActionMessage(org.Username, reqType, extraAction, data) + if err != nil { + errorStr := fmt.Sprintf("hook (%s) processing error: %v\n", reqType, err) + res.Header().Add("Content-Type", "plain/text") + res.Write([]byte(errorStr)) + res.WriteHeader(http.StatusBadRequest) - if DebugMode { - log.Println(errorStr) - } - } else {*/ + if DebugMode { + log.Println(errorStr) + } + } res.WriteHeader(http.StatusOK) - // } }) http.HandleFunc("POST /rabbitmq-forwarder/{Org}", func(res http.ResponseWriter, req *http.Request) {