Skip to content

Commit cbfe7cb

Browse files
committed
feat: [PIPE-28869]: Added support for pull_request_review
1 parent 6ba5ff5 commit cbfe7cb

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

scm/driver/github/webhook.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
5050
hook, err = s.parseReleaseHook(data)
5151
case "workflow_run":
5252
hook, err = s.parsePipelineHook(data)
53+
case "pull_request_review":
54+
hook, err = s.parsePullRequestReviewHook(data)
55+
5356
default:
5457
return nil, scm.ErrUnknownEvent
5558
}
@@ -184,6 +187,26 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error)
184187
return dst, nil
185188
}
186189

190+
func (s *webhookService) parsePullRequestReviewHook(data []byte) (scm.Webhook, error) {
191+
src := new(pullRequestReviewHook)
192+
err := json.Unmarshal(data, src)
193+
if err != nil {
194+
return nil, err
195+
}
196+
dst := convertPullRequestReviewHook(src)
197+
switch src.Action {
198+
case "submitted":
199+
dst.Action = scm.ActionCreate
200+
case "edited":
201+
dst.Action = scm.ActionUpdate
202+
case "dismissed":
203+
dst.Action = scm.ActionDelete
204+
default:
205+
dst.Action = scm.ActionUnknown
206+
}
207+
return dst, nil
208+
}
209+
187210
func (s *webhookService) parsePipelineHook(data []byte) (scm.Webhook, error) {
188211
src := new(pipelineHook)
189212
err := json.Unmarshal(data, src)
@@ -358,6 +381,14 @@ type (
358381
Sender user `json:"sender"`
359382
}
360383

384+
pullRequestReviewHook struct {
385+
Action string `json:"action"`
386+
Number int `json:"number"`
387+
PullRequest pr `json:"pull_request"`
388+
Repository repository `json:"repository"`
389+
Sender user `json:"sender"`
390+
}
391+
361392
// github deployment webhook payload
362393
deploymentHook struct {
363394
Deployment struct {
@@ -615,6 +646,15 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
615646
}
616647
}
617648

649+
func convertPullRequestReviewHook(src *pullRequestReviewHook) *scm.PullRequestReviewHook {
650+
return &scm.PullRequestReviewHook{
651+
// Action Action
652+
Repo: *convertRepository(&src.Repository),
653+
PullRequest: *convertPullRequest(&src.PullRequest),
654+
Sender: *convertUser(&src.Sender),
655+
}
656+
}
657+
618658
func convertDeploymentHook(src *deploymentHook) *scm.DeployHook {
619659
dst := &scm.DeployHook{
620660
Number: src.Deployment.ID,

scm/webhook.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ type (
9191
Sender User
9292
}
9393

94+
PullRequestReviewHook struct {
95+
Action Action
96+
Repo Repository
97+
PullRequest PullRequest
98+
Sender User
99+
}
100+
94101
// PullRequestCommentHook represents an pull request
95102
// comment event, eg pull_request_comment.
96103
PullRequestCommentHook struct {
@@ -160,3 +167,4 @@ func (h *PullRequestCommentHook) Repository() Repository { return h.Repo }
160167
func (h *ReviewCommentHook) Repository() Repository { return h.Repo }
161168
func (h *ReleaseHook) Repository() Repository { return h.Repo }
162169
func (h *PipelineHook) Repository() Repository { return h.Repo }
170+
func (h *PullRequestReviewHook) Repository() Repository { return h.Repo }

0 commit comments

Comments
 (0)