Skip to content

Commit 352d8aa

Browse files
authored
Merge pull request #339 from drone/PIPE-28869
feat: [PIPE-28869]: Added support for pull_request_review
2 parents 3a9d633 + 94cbf99 commit 352d8aa

File tree

7 files changed

+833
-0
lines changed

7 files changed

+833
-0
lines changed

scm/const.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const (
4848
ActionUnpublish
4949
ActionPrerelease
5050
ActionRelease
51+
ActionSubmitted
52+
ActionDismissed
5153
)
5254

5355
// String returns the string representation of Action.
@@ -83,6 +85,12 @@ func (a Action) String() (s string) {
8385
return "released"
8486
case ActionReviewReady:
8587
return "review_ready"
88+
case ActionSubmitted:
89+
return "submitted"
90+
case ActionEdit:
91+
return "edited"
92+
case ActionDismissed:
93+
return "dismissed"
8694
default:
8795
return
8896
}
@@ -132,6 +140,10 @@ func (a *Action) UnmarshalJSON(data []byte) error {
132140
*a = ActionRelease
133141
case "review_ready":
134142
*a = ActionReviewReady
143+
case "submitted":
144+
*a = ActionSubmitted
145+
case "dismissed":
146+
*a = ActionDismissed
135147
}
136148
return nil
137149
}

scm/driver/github/testdata/webhooks/pr_review_edited.json

Lines changed: 541 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"Action": "edited",
3+
"Repo": {
4+
"ID": "335170389",
5+
"Namespace": "shivamnegi94",
6+
"Name": "testrepo",
7+
"Branch": "main",
8+
"Private": false,
9+
"Link": "https://github.com/shivamnegi94/testrepo",
10+
"Created": "2021-02-02T04:41:22Z",
11+
"Updated": "2025-07-29T06:43:46Z",
12+
"Visibility": 1,
13+
"Perm": {},
14+
"CloneSSH": "[email protected]:shivamnegi94/testrepo.git",
15+
"Clone": "https://github.com/shivamnegi94/testrepo.git"
16+
},
17+
"PullRequest": {
18+
"Number": 206,
19+
"Title": "Update sacsac.yaml",
20+
"Body": null,
21+
"Sha": "9dc1b02c9b25bac779bdb2f31034f3f2421aa71d",
22+
"Ref": "refs/pull/206/head",
23+
"Source": "ut",
24+
"Target": "main",
25+
"Fork": "shivamnegi94/testrepo",
26+
"Link": "https://github.com/shivamnegi94/testrepo/pull/206",
27+
"Diff": "https://github.com/shivamnegi94/testrepo/pull/206.diff",
28+
"Closed": false,
29+
"Merged": false,
30+
"Base": {
31+
"Sha": "8115fbff29ce287c1c080ab132ccbb48dee76dcd",
32+
"Path": "refs/heads/main",
33+
"Name": "main"
34+
},
35+
"Head": {
36+
"Sha": "9dc1b02c9b25bac779bdb2f31034f3f2421aa71d",
37+
"Path": "refs/heads/ut",
38+
"Name": "ut"
39+
},
40+
"Author": {
41+
"Login": "utkarshchoubey-harness",
42+
"Name": "",
43+
"Email": "",
44+
"Avatar": "https://avatars.githubusercontent.com/u/101091340?v=4"
45+
},
46+
"Created": "2025-07-29T06:44:39Z",
47+
"Updated": "2025-07-29T06:50:15Z"
48+
},
49+
"Sender": {
50+
"Login": "shivamnegi94",
51+
"Name": "",
52+
"Email": "",
53+
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
54+
}
55+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
{
2+
"action": "submitted",
3+
"review": {
4+
"id": 3060633379,
5+
"node_id": "PRR_kwDOE_pLVc62bY8j",
6+
"user": {
7+
"login": "shivamnegi94",
8+
"id": 58415634,
9+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
10+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4",
11+
"gravatar_id": "",
12+
"url": "https://api.github.com/users/shivamnegi94",
13+
"html_url": "https://github.com/shivamnegi94",
14+
"type": "User",
15+
"site_admin": false
16+
},
17+
"body": "go",
18+
"commit_id": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
19+
"submitted_at": "2025-07-28T06:35:59Z",
20+
"state": "commented",
21+
"html_url": "https://github.com/shivamnegi94/testrepo/pull/205#pullrequestreview-3060633379",
22+
"pull_request_url": "https://api.github.com/repos/shivamnegi94/testrepo/pulls/205",
23+
"author_association": "OWNER"
24+
},
25+
"pull_request": {
26+
"url": "https://api.github.com/repos/shivamnegi94/testrepo/pulls/205",
27+
"id": 2699141628,
28+
"node_id": "PR_kwDOE_pLVc6g4aH8",
29+
"html_url": "https://github.com/shivamnegi94/testrepo/pull/205",
30+
"diff_url": "https://github.com/shivamnegi94/testrepo/pull/205.diff",
31+
"patch_url": "https://github.com/shivamnegi94/testrepo/pull/205.patch",
32+
"issue_url": "https://api.github.com/repos/shivamnegi94/testrepo/issues/205",
33+
"number": 205,
34+
"state": "open",
35+
"locked": false,
36+
"title": "Update NewSre_v1.yaml",
37+
"user": {
38+
"login": "shivamnegi94",
39+
"id": 58415634,
40+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
41+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
42+
},
43+
"body": null,
44+
"created_at": "2025-07-28T04:57:11Z",
45+
"updated_at": "2025-07-28T06:35:59Z",
46+
"closed_at": null,
47+
"merged_at": null,
48+
"merge_commit_sha": "728c82839639b8693c56c4237675deeca6b82163",
49+
"draft": false,
50+
"head": {
51+
"label": "shivamnegi94:shivamnegi94-patch-66",
52+
"ref": "shivamnegi94-patch-66",
53+
"sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
54+
"user": {
55+
"login": "shivamnegi94",
56+
"id": 58415634,
57+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
58+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
59+
},
60+
"repo": {
61+
"id": 335170389,
62+
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
63+
"name": "testrepo",
64+
"full_name": "shivamnegi94/testrepo",
65+
"private": false,
66+
"owner": {
67+
"login": "shivamnegi94",
68+
"id": 58415634,
69+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
70+
},
71+
"html_url": "https://github.com/shivamnegi94/testrepo",
72+
"default_branch": "main",
73+
"visibility": "public"
74+
}
75+
},
76+
"base": {
77+
"label": "shivamnegi94:main",
78+
"ref": "main",
79+
"sha": "28e98f8dc20d4b20eb73b659e16f9fddeb860db5",
80+
"user": {
81+
"login": "shivamnegi94",
82+
"id": 58415634,
83+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
84+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
85+
},
86+
"repo": {
87+
"id": 335170389,
88+
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
89+
"name": "testrepo",
90+
"full_name": "shivamnegi94/testrepo",
91+
"private": false,
92+
"owner": {
93+
"login": "shivamnegi94",
94+
"id": 58415634,
95+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
96+
},
97+
"html_url": "https://github.com/shivamnegi94/testrepo",
98+
"default_branch": "main",
99+
"visibility": "public"
100+
}
101+
}
102+
},
103+
"repository": {
104+
"id": 335170389,
105+
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
106+
"name": "testrepo",
107+
"full_name": "shivamnegi94/testrepo",
108+
"private": false,
109+
"owner": {
110+
"login": "shivamnegi94",
111+
"id": 58415634,
112+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
113+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
114+
},
115+
"html_url": "https://github.com/shivamnegi94/testrepo",
116+
"default_branch": "main",
117+
"visibility": "public"
118+
},
119+
"sender": {
120+
"login": "shivamnegi94",
121+
"id": 58415634,
122+
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
123+
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4",
124+
"type": "User",
125+
"site_admin": false
126+
}
127+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"Action": "submitted",
3+
"Repo": {
4+
"ID": "335170389",
5+
"Namespace": "shivamnegi94",
6+
"Name": "testrepo",
7+
"Branch": "main",
8+
"Private": false,
9+
"Link": "https://github.com/shivamnegi94/testrepo",
10+
"Created": "0001-01-01T00:00:00Z",
11+
"Updated": "0001-01-01T00:00:00Z",
12+
"Visibility": 1,
13+
"Perm": {}
14+
},
15+
"PullRequest": {
16+
"Number": 205,
17+
"Title": "Update NewSre_v1.yaml",
18+
"Body": null,
19+
"Sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
20+
"Ref": "refs/pull/205/head",
21+
"Source": "shivamnegi94-patch-66",
22+
"Target": "main",
23+
"Fork": "shivamnegi94/testrepo",
24+
"Link": "https://github.com/shivamnegi94/testrepo/pull/205",
25+
"Diff": "https://github.com/shivamnegi94/testrepo/pull/205.diff",
26+
"Closed": false,
27+
"Merged": false,
28+
"Base": {
29+
"Sha": "28e98f8dc20d4b20eb73b659e16f9fddeb860db5",
30+
"Path": "refs/heads/main",
31+
"Name": "main"
32+
},
33+
"Head": {
34+
"Sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
35+
"Path": "refs/heads/shivamnegi94-patch-66",
36+
"Name": "shivamnegi94-patch-66"
37+
},
38+
"Author": {
39+
"Login": "shivamnegi94",
40+
"Name": "",
41+
"Email": "",
42+
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
43+
},
44+
"Created": "2025-07-28T04:57:11Z",
45+
"Updated": "2025-07-28T06:35:59Z"
46+
},
47+
"Sender": {
48+
"Login": "shivamnegi94",
49+
"Name": "",
50+
"Email": "",
51+
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
52+
}
53+
}

scm/driver/github/webhook.go

Lines changed: 32 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(pullRequestHook)
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.ActionSubmitted
200+
case "edited":
201+
dst.Action = scm.ActionEdit
202+
case "dismissed":
203+
dst.Action = scm.ActionDismissed
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)
@@ -615,6 +638,15 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
615638
}
616639
}
617640

641+
func convertPullRequestReviewHook(src *pullRequestHook) *scm.PullRequestHook {
642+
return &scm.PullRequestHook{
643+
// Action Action
644+
Repo: *convertRepository(&src.Repository),
645+
PullRequest: *convertPullRequest(&src.PullRequest),
646+
Sender: *convertUser(&src.Sender),
647+
}
648+
}
649+
618650
func convertDeploymentHook(src *deploymentHook) *scm.DeployHook {
619651
dst := &scm.DeployHook{
620652
Number: src.Deployment.ID,

scm/driver/github/webhook_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,19 @@ func TestWebhooks(t *testing.T) {
173173
after: "testdata/webhooks/pr_unlabeled.json.golden",
174174
obj: new(scm.PullRequestHook),
175175
},
176+
{
177+
event: "pull_request_review",
178+
before: "testdata/webhooks/pr_review_submitted.json",
179+
after: "testdata/webhooks/pr_review_submitted.json.golden",
180+
obj: new(scm.PullRequestHook),
181+
},
182+
183+
{
184+
event: "pull_request_review",
185+
before: "testdata/webhooks/pr_review_edited.json",
186+
after: "testdata/webhooks/pr_review_edited.json.golden",
187+
obj: new(scm.PullRequestHook),
188+
},
176189

177190
//
178191
// deployment

0 commit comments

Comments
 (0)