diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index 29ae23c..4323668 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -32,11 +32,11 @@ func connectToRabbitMQ() { go ConnectToExchangeForPublish(host, username, password) } - var id int + func dumpUnhandledData(reqType string, data []byte) { id++ - os.WriteFile("/tmp/unhandled-json-" + reqType + "-" + fmt.Sprint(id) + ".json", data, 0600); + os.WriteFile("/tmp/unhandled-json-"+reqType+"-"+fmt.Sprint(id)+".json", data, 0600) } func main() { @@ -132,18 +132,32 @@ func main() { } return } + switch repoAction.Action { + case "created", "deleted": + break + default: + res.WriteHeader(http.StatusBadRequest) + if DebugMode { + dumpUnhandledData(reqType, data) + } + } org = repoAction.Organization extraAction = repoAction.Action + default: + res.WriteHeader(http.StatusBadRequest) + if DebugMode { + dumpUnhandledData(reqType, data) + } } -// err = PublishMessage(repo.Owner.Username, reqType, data) + // err = PublishMessage(repo.Owner.Username, reqType, data) // write to file for review os.WriteFile("test_data."+fmt.Sprint(connectionId), data, 0644) connectionId++ log.Println(id, org.Username, extraAction) /* - err = PublishMessage(repo.Name, 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") diff --git a/gitea-events-rabbitmq-publisher/rabbitmq.go b/gitea-events-rabbitmq-publisher/rabbitmq.go index ca43c97..da712a7 100644 --- a/gitea-events-rabbitmq-publisher/rabbitmq.go +++ b/gitea-events-rabbitmq-publisher/rabbitmq.go @@ -25,7 +25,7 @@ type Message struct { var messageQueue chan Message -func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) error { +func PublishActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) error { if messageQueue == nil { return fmt.Errorf("Queue not initialized") } @@ -47,10 +47,6 @@ func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) } } - if len(action) > 0 { - msg.Topic = msg.Topic + "." + action - } - select { case messageQueue <- msg: default: @@ -60,7 +56,7 @@ func PublicActionMessage(giteaOrg, giteaWebhookType, action string, data []byte) } func PublishMessage(giteaOrg, giteaWebhookType string, data []byte) error { - return PublicActionMessage(giteaOrg, giteaWebhookType, "", data) + return PublishActionMessage(giteaOrg, giteaWebhookType, "", data) } func ConnectToExchangeForPublish(host, username, password string) {