diff --git a/scm/driver/harness/testdata/webhooks/branch_create.json.golden b/scm/driver/harness/testdata/webhooks/branch_create.json.golden index 0b0dad736..9bc611b39 100644 --- a/scm/driver/harness/testdata/webhooks/branch_create.json.golden +++ b/scm/driver/harness/testdata/webhooks/branch_create.json.golden @@ -26,8 +26,8 @@ "Avatar": "" }, "Committer": { - "Name": "", - "Email": "", + "Name": "Admin", + "Email": "admin@harness.io", "Date": "0001-01-01T00:00:00Z", "Login": "", "Avatar": "" diff --git a/scm/driver/harness/testdata/webhooks/branch_updated.json b/scm/driver/harness/testdata/webhooks/branch_updated.json new file mode 100644 index 000000000..903fea7dd --- /dev/null +++ b/scm/driver/harness/testdata/webhooks/branch_updated.json @@ -0,0 +1,50 @@ +{ + "trigger": "branch_updated", + "repo": { + "id": 68, + "path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync", + "uid": "abhinav-git-sync", + "default_branch": "master", + "git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git" + }, + "principal": { + "id": 59, + "uid": "ec9UfvFwTf663F47Hlqxbg", + "display_name": "abhinav.singh@harness.io", + "email": "abhinav.singh@harness.io", + "type": "user", + "created": 1697617589873, + "updated": 1697617589873 + }, + "ref": { + "name": "refs/heads/master", + "repo": { + "id": 68, + "path": "vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync", + "uid": "abhinav-git-sync", + "default_branch": "master", + "git_url": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git" + } + }, + "sha": "92e21bfcddc1418079cddbb518ad6fd72917798a", + "commit": { + "sha": "92e21bfcddc1418079cddbb518ad6fd72917798a", + "message": "Create asdsad (#2)", + "author": { + "identity": { + "name": "abhinav.singh@harness.io", + "email": "abhinav.singh@harness.io" + }, + "when": "2023-12-05T11:59:39Z" + }, + "committer": { + "identity": { + "name": "Harness", + "email": "noreply@harness.io" + }, + "when": "2023-12-05T11:59:39Z" + } + }, + "old_sha": "a273c385628167932e10caaa58e12550c491f241", + "forced": false +} \ No newline at end of file diff --git a/scm/driver/harness/testdata/webhooks/branch_updated.json.golden b/scm/driver/harness/testdata/webhooks/branch_updated.json.golden new file mode 100644 index 000000000..1537f8d87 --- /dev/null +++ b/scm/driver/harness/testdata/webhooks/branch_updated.json.golden @@ -0,0 +1,46 @@ +{ + "Ref": "92e21bfcddc1418079cddbb518ad6fd72917798a", + "Before": "a273c385628167932e10caaa58e12550c491f241", + "After": "92e21bfcddc1418079cddbb518ad6fd72917798a", + "Repo": { + "ID": "68", + "Namespace": "", + "Name": "abhinav-git-sync", + "Perm": null, + "Branch": "master", + "Private": false, + "Clone": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git", + "CloneSSH": "", + "Link": "https://git.harness.io/vpCkHKsDSxK9_KYfjCTMKA/default/Repo_With_PR_checks/abhinav-git-sync.git", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Commit": { + "Sha": "92e21bfcddc1418079cddbb518ad6fd72917798a", + "Message": "Create asdsad (#2)", + "Author": { + "Name": "abhinav.singh@harness.io", + "Email": "abhinav.singh@harness.io", + "Date" : "0001-01-01T00:00:00Z", + "Login": "", + "Avatar": "" + }, + "Committer": { + "Name": "Harness", + "Email": "noreply@harness.io", + "Date": "0001-01-01T00:00:00Z", + "Login": "", + "Avatar": "" + }, + "Link": "" + }, + "Sender": { + "ID": "ec9UfvFwTf663F47Hlqxbg", + "Login": "ec9UfvFwTf663F47Hlqxbg", + "Name": "abhinav.singh@harness.io", + "Email": "abhinav.singh@harness.io", + "Avatar": "", + "Created": "2023-10-18T13:56:29.873+05:30", + "Updated": "2023-10-18T13:56:29.873+05:30" + } +} \ No newline at end of file diff --git a/scm/driver/harness/webhook.go b/scm/driver/harness/webhook.go index 1c63738aa..d1ce064fd 100644 --- a/scm/driver/harness/webhook.go +++ b/scm/driver/harness/webhook.go @@ -37,7 +37,7 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo // hook, err = s.parseDeleteHook(data) // case "issues": // hook, err = s.parseIssueHook(data) - case "branch_created": + case "branch_created", "branch_updated": hook, err = s.parsePushHook(data) case "pullreq_created", "pullreq_reopened", "pullreq_branch_updated": hook, err = s.parsePullRequestHook(data) @@ -230,6 +230,10 @@ func convertPushHook(src *pushHook) *scm.PushHook { Name: src.Commit.Author.Identity.Name, Email: src.Commit.Author.Identity.Email, }, + Committer: scm.Signature{ + Name: src.Commit.Committer.Identity.Name, + Email: src.Commit.Committer.Identity.Email, + }, }, Sender: convertUser(src.Principal), } diff --git a/scm/driver/harness/webhook_test.go b/scm/driver/harness/webhook_test.go index 175115e61..5e8d7cdf2 100644 --- a/scm/driver/harness/webhook_test.go +++ b/scm/driver/harness/webhook_test.go @@ -33,6 +33,13 @@ func TestWebhooks(t *testing.T) { after: "testdata/webhooks/branch_create.json.golden", obj: new(scm.PushHook), }, + // push branch update + { + event: "branch_updated", + before: "testdata/webhooks/branch_updated.json", + after: "testdata/webhooks/branch_updated.json.golden", + obj: new(scm.PushHook), + }, // // pull request events //