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
}
func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestAction) *models.PullRequest {
func (h *RequestHandler) GetAssociatedPrjGitPR(pr *PullRequestWebhookEvent) *models.PullRequest {
if h.HasError() {
return nil
}

View File

@ -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)
}

View File

@ -170,11 +170,22 @@ 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)