From aadb57588cec49f19dafe8b01b958a21819371b6199496a4a5f86dc80c42eca9 Mon Sep 17 00:00:00 2001 From: Adam Majer Date: Sat, 24 Aug 2024 22:03:30 +0200 Subject: [PATCH] . --- bots-common/request_issue.go | 20 ++++++++++++++++++++ gitea-events-rabbitmq-publisher/main.go | 22 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 bots-common/request_issue.go diff --git a/bots-common/request_issue.go b/bots-common/request_issue.go new file mode 100644 index 0000000..4073e58 --- /dev/null +++ b/bots-common/request_issue.go @@ -0,0 +1,20 @@ +package common + +type IssueDetail struct { + Id int + Number int + Html_url string + User *User + Title string + Body string + State string +} + +type IssueWebhookEvent struct { + Action string + + Issue *IssueDetail + Repository *Repository + Sender *User +} + diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index 0214ce7..dce94a9 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -94,6 +94,22 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = release.Repository.Owner extraAction = release.Action + + case "issues": + issue := common.IssueWebhookEvent{} + if err = json.Unmarshal(data, &issue); err != nil { + return + } + switch issue.Action { + case "opened", "closed", "reopened", "edited": + break + default: + err = fmt.Errorf("Unknown Issue webhook action type: %s", issue.Action) + return + } + org = issue.Repository.Owner + extraAction = issue.Action + default: err = fmt.Errorf("Unknown webhook request type: %s", reqType) } @@ -151,7 +167,7 @@ func main() { org, extraAction, err := parseRequestJSON(reqType, data) if err != nil { res.WriteHeader(http.StatusBadRequest) - log.Printf("error parsing webhook %s JSON. err: %v", reqType, err) + log.Printf("error parsing webhook %s JSON. err: %v", reqType, err) if DebugMode { dumpUnhandledData(reqType, data) } @@ -161,7 +177,9 @@ func main() { // write to file for review id++ os.WriteFile("test_data."+fmt.Sprint(id), data, 0644) - log.Println(id, org.Username, reqType, extraAction) + if org != nil { + log.Println(id, org.Username, reqType, extraAction) + } /* err = PublishMessage(org.Name, reqType, extraAction, data)