diff --git a/bots-common/gitea_utils.go b/bots-common/gitea_utils.go index 8486a39..4e7c0c4 100644 --- a/bots-common/gitea_utils.go +++ b/bots-common/gitea_utils.go @@ -406,7 +406,7 @@ func (h *RequestHandler) AddReviewComment(pr *models.PullRequest, state models.R return c.Payload, nil } -func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.PullRequest { +func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) *models.PullRequest { if h.HasError() { return nil } diff --git a/bots-common/request_pr.go b/bots-common/request_pr.go index 374fa0f..9f5e0bd 100644 --- a/bots-common/request_pr.go +++ b/bots-common/request_pr.go @@ -25,7 +25,7 @@ type PullRequest struct { User User } -type PullRequestAction struct { +type PullRequestWebhookEvent struct { Action string Number int @@ -34,12 +34,12 @@ type PullRequestAction struct { Sender User } -func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction { +func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestWebhookEvent { if h.HasError() { return nil } - var action PullRequestAction + var action PullRequestWebhookEvent h.Error = json.NewDecoder(data).Decode(&action) if h.HasError() { @@ -60,7 +60,7 @@ func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction { return &action } -func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestAction { +func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestWebhookEvent { return h.parsePullRequest(data) } diff --git a/gitea-events-rabbitmq-publisher/main.go b/gitea-events-rabbitmq-publisher/main.go index e026a16..7342b63 100644 --- a/gitea-events-rabbitmq-publisher/main.go +++ b/gitea-events-rabbitmq-publisher/main.go @@ -170,10 +170,21 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex org = issue.Repository.Owner extraAction = issue.Action - + case "pull_request": + pr := common.PullRequestWebhookEvent{} + if err = json.Unmarshal(data, &pr); err != nil { + return + } + switch pr.Action { + case "opened", "closed", "reopened", "edited": + break + default: + err = fmt.Errorf("Unknown PR webhook action type: %s", pr.Action) + return + } + org = pr.Repository.Owner + extraAction = pr.Action -// case "issue_comment": -// case "issue_labelled": default: err = fmt.Errorf("Unknown webhook request type: %s", reqType) @@ -236,6 +247,7 @@ func main() { if DebugMode { dumpUnhandledData(reqType, data) } + // return } // err = PublishMessage(repo.Owner.Username, reqType, data)