This commit is contained in:
Adam Majer 2024-08-25 22:47:44 +02:00
parent b8c7f6c44c
commit e0134baadc
3 changed files with 20 additions and 8 deletions

View File

@ -406,7 +406,7 @@ func (h *RequestHandler) AddReviewComment(pr *models.PullRequest, state models.R
return c.Payload, nil return c.Payload, nil
} }
func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.PullRequest { func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) *models.PullRequest {
if h.HasError() { if h.HasError() {
return nil return nil
} }

View File

@ -25,7 +25,7 @@ type PullRequest struct {
User User User User
} }
type PullRequestAction struct { type PullRequestWebhookEvent struct {
Action string Action string
Number int Number int
@ -34,12 +34,12 @@ type PullRequestAction struct {
Sender User Sender User
} }
func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction { func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestWebhookEvent {
if h.HasError() { if h.HasError() {
return nil return nil
} }
var action PullRequestAction var action PullRequestWebhookEvent
h.Error = json.NewDecoder(data).Decode(&action) h.Error = json.NewDecoder(data).Decode(&action)
if h.HasError() { if h.HasError() {
@ -60,7 +60,7 @@ func (h *RequestHandler) parsePullRequest(data io.Reader) *PullRequestAction {
return &action return &action
} }
func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestAction { func (h *RequestHandler) parsePullRequestSync(data io.Reader) *PullRequestWebhookEvent {
return h.parsePullRequest(data) return h.parsePullRequest(data)
} }

View File

@ -170,10 +170,21 @@ func parseRequestJSON(reqType string, data []byte) (org *common.Organization, ex
org = issue.Repository.Owner org = issue.Repository.Owner
extraAction = issue.Action 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: default:
err = fmt.Errorf("Unknown webhook request type: %s", reqType) err = fmt.Errorf("Unknown webhook request type: %s", reqType)
@ -236,6 +247,7 @@ func main() {
if DebugMode { if DebugMode {
dumpUnhandledData(reqType, data) dumpUnhandledData(reqType, data)
} }
// return
} }
// err = PublishMessage(repo.Owner.Username, reqType, data) // err = PublishMessage(repo.Owner.Username, reqType, data)