Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ const (
ActionUnpublish
ActionPrerelease
ActionRelease
ActionSubmitted
ActionDismissed
)

// String returns the string representation of Action.
Expand Down Expand Up @@ -83,6 +85,12 @@ func (a Action) String() (s string) {
return "released"
case ActionReviewReady:
return "review_ready"
case ActionSubmitted:
return "submitted"
case ActionEdit:
return "edited"
case ActionDismissed:
return "dismissed"
default:
return
}
Expand Down Expand Up @@ -132,6 +140,10 @@ func (a *Action) UnmarshalJSON(data []byte) error {
*a = ActionRelease
case "review_ready":
*a = ActionReviewReady
case "submitted":
*a = ActionSubmitted
case "dismissed":
*a = ActionDismissed
}
return nil
}
Expand Down
541 changes: 541 additions & 0 deletions scm/driver/github/testdata/webhooks/pr_review_edited.json

Large diffs are not rendered by default.

55 changes: 55 additions & 0 deletions scm/driver/github/testdata/webhooks/pr_review_edited.json.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"Action": "edited",
"Repo": {
"ID": "335170389",
"Namespace": "shivamnegi94",
"Name": "testrepo",
"Branch": "main",
"Private": false,
"Link": "https://github.com/shivamnegi94/testrepo",
"Created": "2021-02-02T04:41:22Z",
"Updated": "2025-07-29T06:43:46Z",
"Visibility": 1,
"Perm": {},
"CloneSSH": "git@github.com:shivamnegi94/testrepo.git",
"Clone": "https://github.com/shivamnegi94/testrepo.git"
},
"PullRequest": {
"Number": 206,
"Title": "Update sacsac.yaml",
"Body": null,
"Sha": "9dc1b02c9b25bac779bdb2f31034f3f2421aa71d",
"Ref": "refs/pull/206/head",
"Source": "ut",
"Target": "main",
"Fork": "shivamnegi94/testrepo",
"Link": "https://github.com/shivamnegi94/testrepo/pull/206",
"Diff": "https://github.com/shivamnegi94/testrepo/pull/206.diff",
"Closed": false,
"Merged": false,
"Base": {
"Sha": "8115fbff29ce287c1c080ab132ccbb48dee76dcd",
"Path": "refs/heads/main",
"Name": "main"
},
"Head": {
"Sha": "9dc1b02c9b25bac779bdb2f31034f3f2421aa71d",
"Path": "refs/heads/ut",
"Name": "ut"
},
"Author": {
"Login": "utkarshchoubey-harness",
"Name": "",
"Email": "",
"Avatar": "https://avatars.githubusercontent.com/u/101091340?v=4"
},
"Created": "2025-07-29T06:44:39Z",
"Updated": "2025-07-29T06:50:15Z"
},
"Sender": {
"Login": "shivamnegi94",
"Name": "",
"Email": "",
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
}
}
127 changes: 127 additions & 0 deletions scm/driver/github/testdata/webhooks/pr_review_submitted.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
{
"action": "submitted",
"review": {
"id": 3060633379,
"node_id": "PRR_kwDOE_pLVc62bY8j",
"user": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/shivamnegi94",
"html_url": "https://github.com/shivamnegi94",
"type": "User",
"site_admin": false
},
"body": "go",
"commit_id": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
"submitted_at": "2025-07-28T06:35:59Z",
"state": "commented",
"html_url": "https://github.com/shivamnegi94/testrepo/pull/205#pullrequestreview-3060633379",
"pull_request_url": "https://api.github.com/repos/shivamnegi94/testrepo/pulls/205",
"author_association": "OWNER"
},
"pull_request": {
"url": "https://api.github.com/repos/shivamnegi94/testrepo/pulls/205",
"id": 2699141628,
"node_id": "PR_kwDOE_pLVc6g4aH8",
"html_url": "https://github.com/shivamnegi94/testrepo/pull/205",
"diff_url": "https://github.com/shivamnegi94/testrepo/pull/205.diff",
"patch_url": "https://github.com/shivamnegi94/testrepo/pull/205.patch",
"issue_url": "https://api.github.com/repos/shivamnegi94/testrepo/issues/205",
"number": 205,
"state": "open",
"locked": false,
"title": "Update NewSre_v1.yaml",
"user": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"body": null,
"created_at": "2025-07-28T04:57:11Z",
"updated_at": "2025-07-28T06:35:59Z",
"closed_at": null,
"merged_at": null,
"merge_commit_sha": "728c82839639b8693c56c4237675deeca6b82163",
"draft": false,
"head": {
"label": "shivamnegi94:shivamnegi94-patch-66",
"ref": "shivamnegi94-patch-66",
"sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
"user": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"repo": {
"id": 335170389,
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
"name": "testrepo",
"full_name": "shivamnegi94/testrepo",
"private": false,
"owner": {
"login": "shivamnegi94",
"id": 58415634,
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"html_url": "https://github.com/shivamnegi94/testrepo",
"default_branch": "main",
"visibility": "public"
}
},
"base": {
"label": "shivamnegi94:main",
"ref": "main",
"sha": "28e98f8dc20d4b20eb73b659e16f9fddeb860db5",
"user": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"repo": {
"id": 335170389,
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
"name": "testrepo",
"full_name": "shivamnegi94/testrepo",
"private": false,
"owner": {
"login": "shivamnegi94",
"id": 58415634,
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"html_url": "https://github.com/shivamnegi94/testrepo",
"default_branch": "main",
"visibility": "public"
}
}
},
"repository": {
"id": 335170389,
"node_id": "MDEwOlJlcG9zaXRvcnkzMzUxNzAzODk=",
"name": "testrepo",
"full_name": "shivamnegi94/testrepo",
"private": false,
"owner": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"html_url": "https://github.com/shivamnegi94/testrepo",
"default_branch": "main",
"visibility": "public"
},
"sender": {
"login": "shivamnegi94",
"id": 58415634,
"node_id": "MDQ6VXNlcjU4NDE1NjM0",
"avatar_url": "https://avatars.githubusercontent.com/u/58415634?v=4",
"type": "User",
"site_admin": false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"Action": "submitted",
"Repo": {
"ID": "335170389",
"Namespace": "shivamnegi94",
"Name": "testrepo",
"Branch": "main",
"Private": false,
"Link": "https://github.com/shivamnegi94/testrepo",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z",
"Visibility": 1,
"Perm": {}
},
"PullRequest": {
"Number": 205,
"Title": "Update NewSre_v1.yaml",
"Body": null,
"Sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
"Ref": "refs/pull/205/head",
"Source": "shivamnegi94-patch-66",
"Target": "main",
"Fork": "shivamnegi94/testrepo",
"Link": "https://github.com/shivamnegi94/testrepo/pull/205",
"Diff": "https://github.com/shivamnegi94/testrepo/pull/205.diff",
"Closed": false,
"Merged": false,
"Base": {
"Sha": "28e98f8dc20d4b20eb73b659e16f9fddeb860db5",
"Path": "refs/heads/main",
"Name": "main"
},
"Head": {
"Sha": "adccd6c5030261b47e35d0d3798d4ed31a051f6d",
"Path": "refs/heads/shivamnegi94-patch-66",
"Name": "shivamnegi94-patch-66"
},
"Author": {
"Login": "shivamnegi94",
"Name": "",
"Email": "",
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
},
"Created": "2025-07-28T04:57:11Z",
"Updated": "2025-07-28T06:35:59Z"
},
"Sender": {
"Login": "shivamnegi94",
"Name": "",
"Email": "",
"Avatar": "https://avatars.githubusercontent.com/u/58415634?v=4"
}
}
32 changes: 32 additions & 0 deletions scm/driver/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo
hook, err = s.parseReleaseHook(data)
case "workflow_run":
hook, err = s.parsePipelineHook(data)
case "pull_request_review":
hook, err = s.parsePullRequestReviewHook(data)

default:
return nil, scm.ErrUnknownEvent
}
Expand Down Expand Up @@ -184,6 +187,26 @@ func (s *webhookService) parsePullRequestHook(data []byte) (scm.Webhook, error)
return dst, nil
}

func (s *webhookService) parsePullRequestReviewHook(data []byte) (scm.Webhook, error) {
src := new(pullRequestHook)
err := json.Unmarshal(data, src)
if err != nil {
return nil, err
}
dst := convertPullRequestReviewHook(src)
switch src.Action {
case "submitted":
dst.Action = scm.ActionSubmitted
case "edited":
dst.Action = scm.ActionEdit
case "dismissed":
dst.Action = scm.ActionDismissed
default:
dst.Action = scm.ActionUnknown
}
return dst, nil
}

func (s *webhookService) parsePipelineHook(data []byte) (scm.Webhook, error) {
src := new(pipelineHook)
err := json.Unmarshal(data, src)
Expand Down Expand Up @@ -615,6 +638,15 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
}
}

func convertPullRequestReviewHook(src *pullRequestHook) *scm.PullRequestHook {
return &scm.PullRequestHook{
// Action Action
Repo: *convertRepository(&src.Repository),
PullRequest: *convertPullRequest(&src.PullRequest),
Sender: *convertUser(&src.Sender),
}
}

func convertDeploymentHook(src *deploymentHook) *scm.DeployHook {
dst := &scm.DeployHook{
Number: src.Deployment.ID,
Expand Down
13 changes: 13 additions & 0 deletions scm/driver/github/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,19 @@ func TestWebhooks(t *testing.T) {
after: "testdata/webhooks/pr_unlabeled.json.golden",
obj: new(scm.PullRequestHook),
},
{
event: "pull_request_review",
before: "testdata/webhooks/pr_review_submitted.json",
after: "testdata/webhooks/pr_review_submitted.json.golden",
obj: new(scm.PullRequestHook),
},

{
event: "pull_request_review",
before: "testdata/webhooks/pr_review_edited.json",
after: "testdata/webhooks/pr_review_edited.json.golden",
obj: new(scm.PullRequestHook),
},

//
// deployment
Expand Down