From c7f09d3e2a5c85978b0fbebe222bcb7e85077607 Mon Sep 17 00:00:00 2001 From: raghavharness Date: Sun, 19 Jun 2022 12:29:24 +0530 Subject: [PATCH 1/5] [CI-4623] - Azure webhook parseAPI changes --- .../azure/testdata/webhooks/pr_created.json | 3 +- .../testdata/webhooks/pr_created.json.golden | 18 ++-- .../azure/testdata/webhooks/pr_merged.json | 3 +- .../testdata/webhooks/pr_merged.json.golden | 18 ++-- .../azure/testdata/webhooks/pr_updated.json | 3 +- .../testdata/webhooks/pr_updated.json.golden | 18 ++-- .../azure/testdata/webhooks/push.json.golden | 31 ++++-- scm/driver/azure/webhook.go | 98 ++++++++++++++----- 8 files changed, 129 insertions(+), 63 deletions(-) diff --git a/scm/driver/azure/testdata/webhooks/pr_created.json b/scm/driver/azure/testdata/webhooks/pr_created.json index 746cacec8..9b544c962 100644 --- a/scm/driver/azure/testdata/webhooks/pr_created.json +++ b/scm/driver/azure/testdata/webhooks/pr_created.json @@ -24,7 +24,8 @@ "url": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", "state": "wellFormed" }, - "defaultBranch": "refs/heads/master", + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "remoteUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam" }, "pullRequestId": 1, diff --git a/scm/driver/azure/testdata/webhooks/pr_created.json.golden b/scm/driver/azure/testdata/webhooks/pr_created.json.golden index 3ca595b6c..e081e85fa 100644 --- a/scm/driver/azure/testdata/webhooks/pr_created.json.golden +++ b/scm/driver/azure/testdata/webhooks/pr_created.json.golden @@ -1,17 +1,17 @@ { - "Action": "opened", + "Action": "created", "Repo": { "ID": "4bc14d40-c903-45e2-872e-0462c7748079", "Namespace": "Fabrikam", - "Name": "4bc14d40-c903-45e2-872e-0462c7748079", + "Name": "Fabrikam", "Perm": null, "Branch": "", "Archived": false, "Private": false, "Visibility": 0, - "Clone": "", - "CloneSSH": "", - "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "Created": "0001-01-01T00:00:00Z", "Updated": "0001-01-01T00:00:00Z" }, @@ -19,10 +19,10 @@ "Number": 1, "Title": "my first pull request", "Body": " - test2\r\n", - "Sha": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", "Ref": "refs/heads/mytopic", - "Source": "refs/heads/mytopic", - "Target": "refs/heads/master", + "Source": "mytopic", + "Target": "master", "Fork": "", "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", "Diff": "", @@ -39,7 +39,7 @@ "Sha": "" }, "Author": { - "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Login": "Jamal Hartnett", "Name": "Jamal Hartnett", "Email": "fabrikamfiber4@hotmail.com", "Avatar": "https://dev.azure.com/fabrikam/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", diff --git a/scm/driver/azure/testdata/webhooks/pr_merged.json b/scm/driver/azure/testdata/webhooks/pr_merged.json index 2cdd4a359..15537ac3e 100644 --- a/scm/driver/azure/testdata/webhooks/pr_merged.json +++ b/scm/driver/azure/testdata/webhooks/pr_merged.json @@ -24,7 +24,8 @@ "url": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", "state": "wellFormed" }, - "defaultBranch": "refs/heads/master", + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "remoteUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam" }, "pullRequestId": 1, diff --git a/scm/driver/azure/testdata/webhooks/pr_merged.json.golden b/scm/driver/azure/testdata/webhooks/pr_merged.json.golden index 0b9fcf117..844d14542 100644 --- a/scm/driver/azure/testdata/webhooks/pr_merged.json.golden +++ b/scm/driver/azure/testdata/webhooks/pr_merged.json.golden @@ -3,15 +3,15 @@ "Repo": { "ID": "4bc14d40-c903-45e2-872e-0462c7748079", "Namespace": "Fabrikam", - "Name": "4bc14d40-c903-45e2-872e-0462c7748079", + "Name": "Fabrikam", "Perm": null, "Branch": "", "Archived": false, "Private": false, "Visibility": 0, - "Clone": "", - "CloneSSH": "", - "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "Created": "0001-01-01T00:00:00Z", "Updated": "0001-01-01T00:00:00Z" }, @@ -19,15 +19,15 @@ "Number": 1, "Title": "my first pull request", "Body": " - test2\r\n", - "Sha": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", "Ref": "refs/heads/mytopic", - "Source": "refs/heads/mytopic", - "Target": "refs/heads/master", + "Source": "mytopic", + "Target": "master", "Fork": "", "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", "Diff": "", "Closed": false, - "Merged": false, + "Merged": true, "Base": { "Name": "", "Path": "", @@ -39,7 +39,7 @@ "Sha": "" }, "Author": { - "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Login": "Jamal Hartnett", "Name": "Jamal Hartnett", "Email": "fabrikamfiber4@hotmail.com", "Avatar": "https://dev.azure.com/fabrikam/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", diff --git a/scm/driver/azure/testdata/webhooks/pr_updated.json b/scm/driver/azure/testdata/webhooks/pr_updated.json index 25115a743..ac0f7f1ac 100644 --- a/scm/driver/azure/testdata/webhooks/pr_updated.json +++ b/scm/driver/azure/testdata/webhooks/pr_updated.json @@ -24,7 +24,8 @@ "url": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", "state": "wellFormed" }, - "defaultBranch": "refs/heads/master", + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "remoteUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam" }, "pullRequestId": 1, diff --git a/scm/driver/azure/testdata/webhooks/pr_updated.json.golden b/scm/driver/azure/testdata/webhooks/pr_updated.json.golden index aed341d44..ae36b5d5b 100644 --- a/scm/driver/azure/testdata/webhooks/pr_updated.json.golden +++ b/scm/driver/azure/testdata/webhooks/pr_updated.json.golden @@ -3,15 +3,15 @@ "Repo": { "ID": "4bc14d40-c903-45e2-872e-0462c7748079", "Namespace": "Fabrikam", - "Name": "4bc14d40-c903-45e2-872e-0462c7748079", + "Name": "Fabrikam", "Perm": null, "Branch": "", "Archived": false, "Private": false, "Visibility": 0, - "Clone": "", - "CloneSSH": "", - "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", "Created": "0001-01-01T00:00:00Z", "Updated": "0001-01-01T00:00:00Z" }, @@ -19,14 +19,14 @@ "Number": 1, "Title": "my first pull request", "Body": " - test2\r\n", - "Sha": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", "Ref": "refs/heads/mytopic", - "Source": "refs/heads/mytopic", - "Target": "refs/heads/master", + "Source": "mytopic", + "Target": "master", "Fork": "", "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_apis/repos/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", "Diff": "", - "Closed": false, + "Closed": true, "Merged": false, "Base": { "Name": "", @@ -39,7 +39,7 @@ "Sha": "" }, "Author": { - "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Login": "Jamal Hartnett", "Name": "Jamal Hartnett", "Email": "fabrikamfiber4@hotmail.com", "Avatar": "https://dev.azure.com/fabrikam/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", diff --git a/scm/driver/azure/testdata/webhooks/push.json.golden b/scm/driver/azure/testdata/webhooks/push.json.golden index 76073d237..59fae065b 100644 --- a/scm/driver/azure/testdata/webhooks/push.json.golden +++ b/scm/driver/azure/testdata/webhooks/push.json.golden @@ -4,14 +4,14 @@ "After": "33b55f7cb7e7e245323987634f960cf4a6e6bc74", "Repo": { "ID": "278d5cd2-584d-4b63-824a-2ba458937249", - "Namespace": "", + "Namespace": "Fabrikam-Fiber-Git", "Name": "Fabrikam-Fiber-Git", "Perm": null, - "Branch": "", + "Branch": "master", "Private": false, - "Clone": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_apis/repos/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249", + "Clone": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git", "CloneSSH": "", - "Link": "", + "Link": "https://dev.azure.com/fabrikam-fiber-inc/DefaultCollection/_git/Fabrikam-Fiber-Git", "Created": "0001-01-01T00:00:00Z", "Updated": "0001-01-01T00:00:00Z" }, @@ -37,9 +37,26 @@ } ], "Sender": { - "Login": "", - "Name": "", - "Email": "", + "Login": "00067FFED5C7AF52@Live.com", + "Name": "Jamal Hartnett", + "Email": "Windows Live ID\\fabrikamfiber4@hotmail.com", "Avatar": "" + }, + "Commit": { + "Sha": "33b55f7cb7e7e245323987634f960cf4a6e6bc74", + "Message": "", + "Author": { + "Login": "00067FFED5C7AF52@Live.com", + "Name": "Jamal Hartnett", + "Email": "Windows Live ID\\fabrikamfiber4@hotmail.com", + "Avatar": "" + }, + "Committer": { + "Login": "00067FFED5C7AF52@Live.com", + "Name": "Jamal Hartnett", + "Email": "Windows Live ID\\fabrikamfiber4@hotmail.com", + "Avatar": "" + }, + "Link": "" } } \ No newline at end of file diff --git a/scm/driver/azure/webhook.go b/scm/driver/azure/webhook.go index 94bafe10d..ff73ab99c 100644 --- a/scm/driver/azure/webhook.go +++ b/scm/driver/azure/webhook.go @@ -13,6 +13,7 @@ import ( "time" "github.com/drone/go-scm/scm" + "github.com/drone/go-scm/scm/driver/internal/null" ) type webhookService struct { @@ -52,7 +53,7 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo return nil, err } dst := convertCreatePullRequestHook(src) - dst.Action = scm.ActionOpen + dst.Action = scm.ActionCreate return dst, nil case "git.pullrequest.updated": // https://docs.microsoft.com/en-us/azure/devops/service-hooks/events?view=azure-devops#git.pullrequest.updated @@ -102,13 +103,39 @@ func convertPushHook(src *pushHook) *scm.PushHook { }) } dst := &scm.PushHook{ + Commit: scm.Commit{ + Sha: src.Resource.RefUpdates[0].NewObjectID, + Message: "", + Author: scm.Signature{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, + Committer: scm.Signature{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, + Link: "", + }, Ref: src.Resource.RefUpdates[0].Name, Before: src.Resource.RefUpdates[0].OldObjectID, After: src.Resource.RefUpdates[0].NewObjectID, + Sender: scm.User{ + Login: src.Resource.PushedBy.ID, + Name: src.Resource.PushedBy.DisplayName, + Email: src.Resource.PushedBy.UniqueName, + Avatar: src.Resource.PushedBy.ImageURL, + }, Repo: scm.Repository{ - ID: src.Resource.Repository.ID, - Name: src.Resource.Repository.Name, - Clone: src.Resource.Repository.URL, + ID: src.Resource.Repository.ID, + Branch: scm.TrimRef(src.Resource.Repository.DefaultBranch), + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Clone: src.Resource.Repository.RemoteURL, + Link: src.Resource.Repository.RemoteURL, }, Commits: commits, } @@ -121,13 +148,15 @@ func convertCreatePullRequestHook(src *createPullRequestHook) (returnVal *scm.Pu Number: src.Resource.PullRequestID, Title: src.Resource.Title, Body: src.Resource.Description, - Sha: src.Resource.MergeID, + Sha: src.Resource.LastMergeSourceCommit.CommitID, Ref: src.Resource.SourceRefName, - Source: src.Resource.SourceRefName, - Target: src.Resource.TargetRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), Link: src.Resource.URL, + Closed: false, + Merged: false, Author: scm.User{ - Login: src.Resource.CreatedBy.ID, + Login: src.Resource.CreatedBy.DisplayName, Name: src.Resource.CreatedBy.DisplayName, Email: src.Resource.CreatedBy.UniqueName, Avatar: src.Resource.CreatedBy.ImageURL, @@ -136,9 +165,11 @@ func convertCreatePullRequestHook(src *createPullRequestHook) (returnVal *scm.Pu }, Repo: scm.Repository{ ID: src.Resource.Repository.ID, - Name: src.Resource.Repository.ID, - Namespace: src.Resource.Repository.Name, - Link: src.Resource.Repository.URL, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, }, Sender: scm.User{ Login: src.Resource.CreatedBy.ID, @@ -156,13 +187,15 @@ func convertUpdatePullRequestHook(src *updatePullRequestHook) (returnVal *scm.Pu Number: src.Resource.PullRequestID, Title: src.Resource.Title, Body: src.Resource.Description, - Sha: src.Resource.MergeID, + Sha: src.Resource.LastMergeSourceCommit.CommitID, Ref: src.Resource.SourceRefName, - Source: src.Resource.SourceRefName, - Target: src.Resource.TargetRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), Link: src.Resource.URL, + Closed: src.Resource.ClosedDate.Valid, + Merged: false, Author: scm.User{ - Login: src.Resource.CreatedBy.ID, + Login: src.Resource.CreatedBy.DisplayName, Name: src.Resource.CreatedBy.DisplayName, Email: src.Resource.CreatedBy.UniqueName, Avatar: src.Resource.CreatedBy.ImageURL, @@ -171,9 +204,11 @@ func convertUpdatePullRequestHook(src *updatePullRequestHook) (returnVal *scm.Pu }, Repo: scm.Repository{ ID: src.Resource.Repository.ID, - Name: src.Resource.Repository.ID, - Namespace: src.Resource.Repository.Name, - Link: src.Resource.Repository.URL, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, }, Sender: scm.User{ Login: src.Resource.CreatedBy.ID, @@ -191,13 +226,15 @@ func convertMergePullRequestHook(src *mergePullRequestHook) (returnVal *scm.Pull Number: src.Resource.PullRequestID, Title: src.Resource.Title, Body: src.Resource.Description, - Sha: src.Resource.MergeID, + Sha: src.Resource.LastMergeSourceCommit.CommitID, Ref: src.Resource.SourceRefName, - Source: src.Resource.SourceRefName, - Target: src.Resource.TargetRefName, + Source: scm.TrimRef(src.Resource.SourceRefName), + Target: scm.TrimRef(src.Resource.TargetRefName), Link: src.Resource.URL, + Closed: false, + Merged: true, Author: scm.User{ - Login: src.Resource.CreatedBy.ID, + Login: src.Resource.CreatedBy.DisplayName, Name: src.Resource.CreatedBy.DisplayName, Email: src.Resource.CreatedBy.UniqueName, Avatar: src.Resource.CreatedBy.ImageURL, @@ -206,9 +243,11 @@ func convertMergePullRequestHook(src *mergePullRequestHook) (returnVal *scm.Pull }, Repo: scm.Repository{ ID: src.Resource.Repository.ID, - Name: src.Resource.Repository.ID, - Namespace: src.Resource.Repository.Name, - Link: src.Resource.Repository.URL, + Name: src.Resource.Repository.Name, + Namespace: src.Resource.Repository.Project.Name, + Link: src.Resource.Repository.WebURL, + Clone: src.Resource.Repository.WebURL, + CloneSSH: src.Resource.Repository.SSHURL, }, Sender: scm.User{ Login: src.Resource.CreatedBy.ID, @@ -257,6 +296,7 @@ type pushHook struct { DisplayName string `json:"displayName"` ID string `json:"id"` UniqueName string `json:"uniqueName"` + ImageURL string `json:"imageUrl"` } `json:"pushedBy"` RefUpdates []struct { Name string `json:"name"` @@ -313,6 +353,8 @@ type createPullRequestHook struct { ID string `json:"id"` Name string `json:"name"` URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` Project struct { ID string `json:"id"` Name string `json:"name"` @@ -393,7 +435,7 @@ type updatePullRequestHook struct { } `json:"message"` PublisherID string `json:"publisherId"` Resource struct { - ClosedDate string `json:"closedDate"` + ClosedDate null.String `json:"closedDate"` Commits []struct { CommitID string `json:"commitId"` URL string `json:"url"` @@ -434,6 +476,8 @@ type updatePullRequestHook struct { } `json:"project"` RemoteURL string `json:"remoteUrl"` URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` } `json:"repository"` Reviewers []struct { DisplayName string `json:"displayName"` @@ -519,6 +563,8 @@ type mergePullRequestHook struct { } `json:"project"` RemoteURL string `json:"remoteUrl"` URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` } `json:"repository"` Reviewers []struct { DisplayName string `json:"displayName"` From cc265c122bc0edfd118dab4ef6a6b8e0bba5a736 Mon Sep 17 00:00:00 2001 From: Hemanth Mantri Date: Mon, 20 Jun 2022 11:39:23 -0700 Subject: [PATCH 2/5] Fixed formatting in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7ada651d4..a95de0461 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ comment, _, err := client.Issues.CreateComment(ctx, "octocat/Hello-World", 1, in Here are some useful links to providers API documentation: -- [Azure DevOps](https://docs.microsoft.com/en-us/rest/api/azure/devops/git/?view=azure-devops-rest-6.0)) +- [Azure DevOps](https://docs.microsoft.com/en-us/rest/api/azure/devops/git/?view=azure-devops-rest-6.0) - [Bitbucket cloud API](https://developer.atlassian.com/cloud/bitbucket/rest/intro/) - [Bitbucket server/Stash API](https://docs.atlassian.com/bitbucket-server/rest/5.16.0/bitbucket-rest.html) - [Gitea API](https://gitea.com/api/swagger/#/) From 71ecc3b1545f257f51207ad6c8d7f373bbf05636 Mon Sep 17 00:00:00 2001 From: Raghav Date: Tue, 28 Jun 2022 16:12:00 +0530 Subject: [PATCH 3/5] added issue comment hook support for Azure (#200) * added issue comment hook support for Azure * added supported actions --- scm/const.go | 4 + .../testdata/webhooks/issue_comment.json | 132 ++++++++++++ .../webhooks/issue_comment.json.golden | 88 ++++++++ .../webhooks/issue_comment_delete.json | 133 ++++++++++++ .../webhooks/issue_comment_delete.json.golden | 88 ++++++++ .../testdata/webhooks/issue_comment_edit.json | 132 ++++++++++++ .../webhooks/issue_comment_edit.json.golden | 88 ++++++++ scm/driver/azure/webhook.go | 192 ++++++++++++++++++ scm/driver/azure/webhook_test.go | 18 ++ 9 files changed, 875 insertions(+) create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment.json create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment.json.golden create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment_delete.json create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment_delete.json.golden create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment_edit.json create mode 100644 scm/driver/azure/testdata/webhooks/issue_comment_edit.json.golden diff --git a/scm/const.go b/scm/const.go index 576290e70..690202cb5 100644 --- a/scm/const.go +++ b/scm/const.go @@ -67,6 +67,8 @@ func (a Action) String() (s string) { return "synchronized" case ActionMerge: return "merged" + case ActionEdit: + return "edited" default: return } @@ -104,6 +106,8 @@ func (a *Action) UnmarshalJSON(data []byte) error { *a = ActionSync case "merged": *a = ActionMerge + case "edited": + *a = ActionEdit } return nil } diff --git a/scm/driver/azure/testdata/webhooks/issue_comment.json b/scm/driver/azure/testdata/webhooks/issue_comment.json new file mode 100644 index 000000000..33cd10cad --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment.json @@ -0,0 +1,132 @@ +{ + "subscriptionId": "00000000-0000-0000-0000-000000000000", + "notificationId": 2, + "id": "af07be1b-f3ad-44c8-a7f1-c4835f2df06b", + "eventType": "ms.vss-code.git-pullrequest-comment-event", + "publisherId": "tfs", + "message": { + "text": "Jamal Hartnett has edited a pull request comment", + "html": "Jamal Hartnett has edited a pull request comment", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment" + }, + "detailedMessage": { + "text": "Jamal Hartnett has edited a pull request comment\r\nThis is my comment.\r\n", + "html": "Jamal Hartnett has edited a pull request comment

This is my comment.

", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment\r\nThis is my comment.\r\n" + }, + "resource": { + "comment": { + "id": 2, + "parentCommentId": 1, + "author": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "content": "This is my comment.", + "publishedDate": "2014-06-17T16:55:46.589889Z", + "lastUpdatedDate": "2014-06-17T16:55:46.589889Z", + "lastContentUpdatedDate": "2014-06-17T16:58:33.123889Z", + "commentType": "text", + "_links": { + "self": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5/comments/2" + }, + "repository": { + "href": "http://joscol2/DefaultCollection/ebed510c-62eb-474b-965f-fd151ebb82e4/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079" + }, + "threads": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5" + } + } + }, + "pullRequest": { + "repository": { + "id": "4bc14d40-c903-45e2-872e-0462c7748079", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "project": { + "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "state": "wellFormed", + "visibility": "unchanged", + "lastUpdateTime": "0001-01-01T00:00:00" + }, + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam" + }, + "pullRequestId": 1, + "status": "active", + "createdBy": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "creationDate": "2014-06-17T16:55:46.589889Z", + "title": "my first pull request", + "description": " - test2\r\n", + "sourceRefName": "refs/heads/mytopic", + "targetRefName": "refs/heads/master", + "mergeStatus": "succeeded", + "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "lastMergeSourceCommit": { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + }, + "lastMergeTargetCommit": { + "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882" + }, + "lastMergeCommit": { + "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72" + }, + "reviewers": [ + { + "reviewerUrl": null, + "vote": 0, + "displayName": "[Mobile]\\Mobile Team", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c", + "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c", + "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c", + "isContainer": true + } + ], + "commits": [ + { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + } + ], + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "_links": { + "web": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion" + }, + "statuses": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses" + } + } + } + }, + "resourceVersion": "2.0", + "resourceContainers": { + "collection": { + "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2" + }, + "account": { + "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e" + }, + "project": { + "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f" + } + }, + "createdDate": "2022-06-21T13:03:20.480894Z" + } \ No newline at end of file diff --git a/scm/driver/azure/testdata/webhooks/issue_comment.json.golden b/scm/driver/azure/testdata/webhooks/issue_comment.json.golden new file mode 100644 index 000000000..70b4da243 --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment.json.golden @@ -0,0 +1,88 @@ +{ + "Action": "created", + "Repo": { + "ID": "4bc14d40-c903-45e2-872e-0462c7748079", + "Namespace": "Fabrikam", + "Name": "Fabrikam", + "Perm": null, + "Branch": "mytopic", + "Archived": false, + "Private": false, + "Visibility": 0, + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Issue": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "PullRequest": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "Ref": "refs/heads/mytopic", + "Source": "mytopic", + "Target": "master", + "Fork": "", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Diff": "", + "Closed": false, + "Merged": false, + "Base": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Head": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "0001-01-01T00:00:00Z", + "Labels": null + }, + "Created": "2014-06-17T16:55:46.589889Z" + }, + "Comment": { + "ID": 2, + "Body": "This is my comment.", + "Author": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "2014-06-17T16:55:46.589889Z" + }, + "Sender": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + } +} \ No newline at end of file diff --git a/scm/driver/azure/testdata/webhooks/issue_comment_delete.json b/scm/driver/azure/testdata/webhooks/issue_comment_delete.json new file mode 100644 index 000000000..5b154f7b3 --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment_delete.json @@ -0,0 +1,133 @@ +{ + "subscriptionId": "00000000-0000-0000-0000-000000000000", + "notificationId": 2, + "id": "af07be1b-f3ad-44c8-a7f1-c4835f2df06b", + "eventType": "ms.vss-code.git-pullrequest-comment-event", + "publisherId": "tfs", + "message": { + "text": "Jamal Hartnett has edited a pull request comment", + "html": "Jamal Hartnett has edited a pull request comment", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment" + }, + "detailedMessage": { + "text": "Jamal Hartnett has edited a pull request comment\r\nThis is my comment.\r\n", + "html": "Jamal Hartnett has edited a pull request comment

This is my comment.

", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment\r\nThis is my comment.\r\n" + }, + "resource": { + "comment": { + "id": 2, + "parentCommentId": 1, + "author": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "content": "This is my comment.", + "publishedDate": "2014-06-17T16:55:46.589889Z", + "lastUpdatedDate": "2014-06-17T16:58:33.123889Z", + "lastContentUpdatedDate": "2014-06-17T16:58:33.123889Z", + "commentType": "text", + "isDeleted": true, + "_links": { + "self": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5/comments/2" + }, + "repository": { + "href": "http://joscol2/DefaultCollection/ebed510c-62eb-474b-965f-fd151ebb82e4/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079" + }, + "threads": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5" + } + } + }, + "pullRequest": { + "repository": { + "id": "4bc14d40-c903-45e2-872e-0462c7748079", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "project": { + "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "state": "wellFormed", + "visibility": "unchanged", + "lastUpdateTime": "0001-01-01T00:00:00" + }, + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam" + }, + "pullRequestId": 1, + "status": "active", + "createdBy": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "creationDate": "2014-06-17T16:55:46.589889Z", + "title": "my first pull request", + "description": " - test2\r\n", + "sourceRefName": "refs/heads/mytopic", + "targetRefName": "refs/heads/master", + "mergeStatus": "succeeded", + "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "lastMergeSourceCommit": { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + }, + "lastMergeTargetCommit": { + "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882" + }, + "lastMergeCommit": { + "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72" + }, + "reviewers": [ + { + "reviewerUrl": null, + "vote": 0, + "displayName": "[Mobile]\\Mobile Team", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c", + "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c", + "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c", + "isContainer": true + } + ], + "commits": [ + { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + } + ], + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "_links": { + "web": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion" + }, + "statuses": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses" + } + } + } + }, + "resourceVersion": "2.0", + "resourceContainers": { + "collection": { + "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2" + }, + "account": { + "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e" + }, + "project": { + "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f" + } + }, + "createdDate": "2022-06-21T13:03:20.480894Z" + } \ No newline at end of file diff --git a/scm/driver/azure/testdata/webhooks/issue_comment_delete.json.golden b/scm/driver/azure/testdata/webhooks/issue_comment_delete.json.golden new file mode 100644 index 000000000..cd1e33741 --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment_delete.json.golden @@ -0,0 +1,88 @@ +{ + "Action": "deleted", + "Repo": { + "ID": "4bc14d40-c903-45e2-872e-0462c7748079", + "Namespace": "Fabrikam", + "Name": "Fabrikam", + "Perm": null, + "Branch": "mytopic", + "Archived": false, + "Private": false, + "Visibility": 0, + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Issue": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "PullRequest": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "Ref": "refs/heads/mytopic", + "Source": "mytopic", + "Target": "master", + "Fork": "", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Diff": "", + "Closed": false, + "Merged": false, + "Base": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Head": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "0001-01-01T00:00:00Z", + "Labels": null + }, + "Created": "2014-06-17T16:55:46.589889Z" + }, + "Comment": { + "ID": 2, + "Body": "This is my comment.", + "Author": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "2014-06-17T16:58:33.123889Z" + }, + "Sender": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + } +} \ No newline at end of file diff --git a/scm/driver/azure/testdata/webhooks/issue_comment_edit.json b/scm/driver/azure/testdata/webhooks/issue_comment_edit.json new file mode 100644 index 000000000..971daae0d --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment_edit.json @@ -0,0 +1,132 @@ +{ + "subscriptionId": "00000000-0000-0000-0000-000000000000", + "notificationId": 2, + "id": "af07be1b-f3ad-44c8-a7f1-c4835f2df06b", + "eventType": "ms.vss-code.git-pullrequest-comment-event", + "publisherId": "tfs", + "message": { + "text": "Jamal Hartnett has edited a pull request comment", + "html": "Jamal Hartnett has edited a pull request comment", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment" + }, + "detailedMessage": { + "text": "Jamal Hartnett has edited a pull request comment\r\nThis is my comment.\r\n", + "html": "Jamal Hartnett has edited a pull request comment

This is my comment.

", + "markdown": "Jamal Hartnett has [edited](https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5) a pull request comment\r\nThis is my comment.\r\n" + }, + "resource": { + "comment": { + "id": 2, + "parentCommentId": 1, + "author": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "content": "This is my comment.", + "publishedDate": "2014-06-17T16:55:46.589889Z", + "lastUpdatedDate": "2014-06-17T16:58:33.123889Z", + "lastContentUpdatedDate": "2014-06-17T16:58:33.123889Z", + "commentType": "text", + "_links": { + "self": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5/comments/2" + }, + "repository": { + "href": "http://joscol2/DefaultCollection/ebed510c-62eb-474b-965f-fd151ebb82e4/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079" + }, + "threads": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/threads/5" + } + } + }, + "pullRequest": { + "repository": { + "id": "4bc14d40-c903-45e2-872e-0462c7748079", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079", + "project": { + "id": "6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "name": "Fabrikam", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/projects/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c", + "state": "wellFormed", + "visibility": "unchanged", + "lastUpdateTime": "0001-01-01T00:00:00" + }, + "sshUrl": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "webUrl": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "remoteUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam" + }, + "pullRequestId": 1, + "status": "active", + "createdBy": { + "displayName": "Jamal Hartnett", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/54d125f7-69f7-4191-904f-c5b96b6261c8", + "id": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "uniqueName": "fabrikamfiber4@hotmail.com", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8" + }, + "creationDate": "2014-06-17T16:55:46.589889Z", + "title": "my first pull request", + "description": " - test2\r\n", + "sourceRefName": "refs/heads/mytopic", + "targetRefName": "refs/heads/master", + "mergeStatus": "succeeded", + "mergeId": "a10bb228-6ba6-4362-abd7-49ea21333dbd", + "lastMergeSourceCommit": { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + }, + "lastMergeTargetCommit": { + "commitId": "a511f535b1ea495ee0c903badb68fbc83772c882", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/a511f535b1ea495ee0c903badb68fbc83772c882" + }, + "lastMergeCommit": { + "commitId": "eef717f69257a6333f221566c1c987dc94cc0d72", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/eef717f69257a6333f221566c1c987dc94cc0d72" + }, + "reviewers": [ + { + "reviewerUrl": null, + "vote": 0, + "displayName": "[Mobile]\\Mobile Team", + "url": "https://fabrikam.vssps.visualstudio.com/_apis/Identities/2ea2d095-48f9-4cd6-9966-62f6f574096c", + "id": "2ea2d095-48f9-4cd6-9966-62f6f574096c", + "uniqueName": "vstfs:///Classification/TeamProject/f0811a3b-8c8a-4e43-a3bf-9a049b4835bd\\Mobile Team", + "imageUrl": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=2ea2d095-48f9-4cd6-9966-62f6f574096c", + "isContainer": true + } + ], + "commits": [ + { + "commitId": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/commits/53d54ac915144006c2c9e90d2c7d3880920db49c" + } + ], + "url": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "_links": { + "web": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1#view=discussion" + }, + "statuses": { + "href": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1/statuses" + } + } + } + }, + "resourceVersion": "2.0", + "resourceContainers": { + "collection": { + "id": "c12d0eb8-e382-443b-9f9c-c52cba5014c2" + }, + "account": { + "id": "f844ec47-a9db-4511-8281-8b63f4eaf94e" + }, + "project": { + "id": "be9b3917-87e6-42a4-a549-2bc06a7a878f" + } + }, + "createdDate": "2022-06-21T13:03:20.480894Z" + } \ No newline at end of file diff --git a/scm/driver/azure/testdata/webhooks/issue_comment_edit.json.golden b/scm/driver/azure/testdata/webhooks/issue_comment_edit.json.golden new file mode 100644 index 000000000..4ae2669fb --- /dev/null +++ b/scm/driver/azure/testdata/webhooks/issue_comment_edit.json.golden @@ -0,0 +1,88 @@ +{ + "Action": "edited", + "Repo": { + "ID": "4bc14d40-c903-45e2-872e-0462c7748079", + "Namespace": "Fabrikam", + "Name": "Fabrikam", + "Perm": null, + "Branch": "mytopic", + "Archived": false, + "Private": false, + "Visibility": 0, + "Clone": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "CloneSSH": "git@ssh.dev.azure.com:v3/fabrikam/DefaultCollection/Fabrikam", + "Link": "https://dev.azure.com/fabrikam/DefaultCollection/_git/Fabrikam", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Issue": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "PullRequest": { + "Number": 1, + "Title": "my first pull request", + "Body": " - test2\r\n", + "Sha": "53d54ac915144006c2c9e90d2c7d3880920db49c", + "Ref": "refs/heads/mytopic", + "Source": "mytopic", + "Target": "master", + "Fork": "", + "Link": "https://fabrikam.visualstudio.com/DefaultCollection/_apis/git/repositories/4bc14d40-c903-45e2-872e-0462c7748079/pullRequests/1", + "Diff": "", + "Closed": false, + "Merged": false, + "Base": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Head": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Author": { + "Login": "Jamal Hartnett", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Avatar": "https://fabrikam.visualstudio.com/DefaultCollection/_api/_common/identityImage?id=54d125f7-69f7-4191-904f-c5b96b6261c8", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "0001-01-01T00:00:00Z", + "Labels": null + }, + "Created": "2014-06-17T16:55:46.589889Z" + }, + "Comment": { + "ID": 2, + "Body": "This is my comment.", + "Author": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2014-06-17T16:55:46.589889Z", + "Updated": "2014-06-17T16:58:33.123889Z" + }, + "Sender": { + "Login": "54d125f7-69f7-4191-904f-c5b96b6261c8", + "Name": "Jamal Hartnett", + "Email": "fabrikamfiber4@hotmail.com", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + } +} \ No newline at end of file diff --git a/scm/driver/azure/webhook.go b/scm/driver/azure/webhook.go index ff73ab99c..9e17da18f 100644 --- a/scm/driver/azure/webhook.go +++ b/scm/driver/azure/webhook.go @@ -75,11 +75,30 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo dst := convertMergePullRequestHook(src) dst.Action = scm.ActionMerge return dst, nil + case "ms.vss-code.git-pullrequest-comment-event": + src := new(issueCommentPullRequestHook) + err := json.Unmarshal(data, src) + if err != nil { + return nil, err + } + dst := convertIssueCommentHook(src) + dst.Action = getIssueCommentAction(src) + return dst, nil default: return nil, scm.ErrUnknownEvent } } +func getIssueCommentAction(src *issueCommentPullRequestHook) scm.Action { + if src.Resource.Comment.IsDeleted { + return scm.ActionDelete + } else if src.Resource.Comment.PublishedDate.Equal(src.Resource.Comment.LastUpdatedDate) { + return scm.ActionCreate + } else { + return scm.ActionEdit + } +} + func convertPushHook(src *pushHook) *scm.PushHook { var commits []scm.Commit for _, c := range src.Resource.Commits { @@ -259,6 +278,70 @@ func convertMergePullRequestHook(src *mergePullRequestHook) (returnVal *scm.Pull return returnVal } +func convertIssueCommentHook(src *issueCommentPullRequestHook) *scm.IssueCommentHook { + dst := &scm.IssueCommentHook{ + Repo: scm.Repository{ + ID: src.Resource.PullRequest.Repository.ID, + Namespace: src.Resource.PullRequest.Repository.Project.Name, + Name: src.Resource.PullRequest.Repository.Name, + Branch: scm.TrimRef(src.Resource.PullRequest.SourceRefName), + Private: false, + Clone: src.Resource.PullRequest.Repository.WebURL, + CloneSSH: src.Resource.PullRequest.Repository.SSHURL, + Link: src.Resource.PullRequest.Repository.WebURL, + }, + Issue: scm.Issue{ + Number: src.Resource.PullRequest.PullRequestID, + Title: src.Resource.PullRequest.Title, + Body: src.Resource.PullRequest.Description, + Link: src.Resource.PullRequest.URL, + Author: scm.User{ + Login: src.Resource.PullRequest.CreatedBy.DisplayName, + Name: src.Resource.PullRequest.CreatedBy.DisplayName, + Email: src.Resource.PullRequest.CreatedBy.UniqueName, + Avatar: src.Resource.PullRequest.CreatedBy.ImageURL, + }, + PullRequest: scm.PullRequest{ + Number: src.Resource.PullRequest.PullRequestID, + Title: src.Resource.PullRequest.Title, + Body: src.Resource.PullRequest.Description, + Sha: src.Resource.PullRequest.LastMergeSourceCommit.CommitID, + Ref: src.Resource.PullRequest.SourceRefName, + Source: scm.TrimRef(src.Resource.PullRequest.SourceRefName), + Target: scm.TrimRef(src.Resource.PullRequest.TargetRefName), + Link: src.Resource.PullRequest.URL, + Closed: false, + Merged: false, + Author: scm.User{ + Login: src.Resource.PullRequest.CreatedBy.DisplayName, + Name: src.Resource.PullRequest.CreatedBy.DisplayName, + Email: src.Resource.PullRequest.CreatedBy.UniqueName, + Avatar: src.Resource.PullRequest.CreatedBy.ImageURL, + }, + Created: src.Resource.PullRequest.CreationDate, + }, + Created: src.Resource.PullRequest.CreationDate, + }, + Comment: scm.Comment{ + ID: src.Resource.Comment.ID, + Body: src.Resource.Comment.Content, + Author: scm.User{ + Email: src.Resource.Comment.Author.UniqueName, + Login: src.Resource.Comment.Author.ID, + Name: src.Resource.Comment.Author.DisplayName, + }, + Created: src.Resource.Comment.PublishedDate, + Updated: src.Resource.Comment.LastUpdatedDate, + }, + Sender: scm.User{ + Email: src.Resource.Comment.Author.UniqueName, + Login: src.Resource.Comment.Author.ID, + Name: src.Resource.Comment.Author.DisplayName, + }, + } + return dst +} + type pushHook struct { CreatedDate string `json:"createdDate"` DetailedMessage struct { @@ -596,3 +679,112 @@ type mergePullRequestHook struct { ResourceVersion string `json:"resourceVersion"` Scope string `json:"scope"` } + +type issueCommentPullRequestHook struct { + CreatedDate string `json:"createdDate"` + DetailedMessage struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"detailedMessage"` + EventType string `json:"eventType"` + ID string `json:"id"` + Message struct { + HTML string `json:"html"` + Markdown string `json:"markdown"` + Text string `json:"text"` + } `json:"message"` + PublisherID string `json:"publisherId"` + Resource struct { + PullRequest struct { + CreatedBy struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"createdBy"` + CreationDate time.Time `json:"creationDate"` + Description string `json:"description"` + LastMergeCommit struct { + CommitID string `json:"commitId"` + Author struct { + Date time.Time `json:"date"` + Email string `json:"email"` + Name string `json:"name"` + } `json:"author"` + URL string `json:"url"` + } `json:"lastMergeCommit"` + LastMergeSourceCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeSourceCommit"` + LastMergeTargetCommit struct { + CommitID string `json:"commitId"` + URL string `json:"url"` + } `json:"lastMergeTargetCommit"` + MergeID string `json:"mergeId"` + MergeStatus string `json:"mergeStatus"` + PullRequestID int `json:"pullRequestId"` + Repository struct { + ID string `json:"id"` + Name string `json:"name"` + Project struct { + ID string `json:"id"` + Name string `json:"name"` + State string `json:"state"` + URL string `json:"url"` + } `json:"project"` + RemoteURL string `json:"remoteUrl"` + URL string `json:"url"` + WebURL string `json:"webUrl"` + SSHURL string `json:"sshUrl"` + } `json:"repository"` + Reviewers []struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + IsContainer bool `json:"isContainer"` + ReviewerURL interface{} `json:"reviewerUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + Vote int64 `json:"vote"` + } `json:"reviewers"` + SourceRefName string `json:"sourceRefName"` + Status string `json:"status"` + TargetRefName string `json:"targetRefName"` + Title string `json:"title"` + URL string `json:"url"` + } `json:"pullRequest"` + Comment struct { + ID int `json:"id"` + ParentCommentId int `json:"parentCommentId"` + Content string `json:"content"` + PublishedDate time.Time `json:"publishedDate"` + LastUpdatedDate time.Time `json:"lastUpdatedDate"` + LastContentUpdatedDate time.Time `json:"lastContentUpdatedDate"` + CommentType string `json:"commentType"` + IsDeleted bool `json:"isDeleted"` + Author struct { + DisplayName string `json:"displayName"` + ID string `json:"id"` + ImageURL string `json:"imageUrl"` + UniqueName string `json:"uniqueName"` + URL string `json:"url"` + } `json:"author"` + } `json:"comment"` + } `json:"resource"` + ResourceContainers struct { + Account struct { + ID string `json:"id"` + } `json:"account"` + Collection struct { + ID string `json:"id"` + } `json:"collection"` + Project struct { + ID string `json:"id"` + } `json:"project"` + } `json:"resourceContainers"` + ResourceVersion string `json:"resourceVersion"` + Scope string `json:"scope"` +} \ No newline at end of file diff --git a/scm/driver/azure/webhook_test.go b/scm/driver/azure/webhook_test.go index 7ea03870e..d4024c2f8 100644 --- a/scm/driver/azure/webhook_test.go +++ b/scm/driver/azure/webhook_test.go @@ -47,6 +47,24 @@ func TestWebhooks(t *testing.T) { after: "testdata/webhooks/pr_merged.json.golden", obj: new(scm.PullRequestHook), }, + // issue comment create + { + before: "testdata/webhooks/issue_comment.json", + after: "testdata/webhooks/issue_comment.json.golden", + obj: new(scm.IssueCommentHook), + }, + // issue comment edit + { + before: "testdata/webhooks/issue_comment_edit.json", + after: "testdata/webhooks/issue_comment_edit.json.golden", + obj: new(scm.IssueCommentHook), + }, + // issue comment delete + { + before: "testdata/webhooks/issue_comment_delete.json", + after: "testdata/webhooks/issue_comment_delete.json.golden", + obj: new(scm.IssueCommentHook), + }, } for _, test := range tests { From 152fbb89839c65c859b065ec7e40156521651ed4 Mon Sep 17 00:00:00 2001 From: Rutvij Mehta Date: Thu, 23 Jun 2022 18:50:48 -0700 Subject: [PATCH 4/5] Support parsing PR comment events for Bitbucket Cloud --- .../testdata/webhooks/pr_comment_created.json | 331 ++++++++++++++++++ .../webhooks/pr_comment_created.json.golden | 96 +++++ .../testdata/webhooks/pr_comment_deleted.json | 305 ++++++++++++++++ .../webhooks/pr_comment_deleted.json.golden | 96 +++++ scm/driver/bitbucket/webhook.go | 279 +++++++++++++++ scm/driver/bitbucket/webhook_test.go | 14 + scm/user.go | 1 + 7 files changed, 1122 insertions(+) create mode 100644 scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json create mode 100644 scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json.golden create mode 100644 scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json create mode 100644 scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json.golden diff --git a/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json b/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json new file mode 100644 index 000000000..b13056f91 --- /dev/null +++ b/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json @@ -0,0 +1,331 @@ +{ + "comment": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/comments/311512047" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1/_/diff#comment-311512047" + } + }, + "deleted": false, + "pullrequest": { + "type": "pullrequest", + "id": 1, + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1" + } + }, + "title": "Update pom.xml" + }, + "content": { + "raw": "test comment", + "markup": "markdown", + "html": "

test comment

", + "type": "rendered" + }, + "created_on": "2022-06-23T22:10:09.939925+00:00", + "user": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "updated_on": "2022-06-23T22:10:09.939978+00:00", + "type": "pullrequest_comment", + "id": 311512047 + }, + "pullrequest": { + "rendered": { + "description": { + "raw": "Test", + "markup": "markdown", + "html": "

Test

", + "type": "rendered" + }, + "title": { + "raw": "Update pom.xml", + "markup": "markdown", + "html": "

Update pom.xml

", + "type": "rendered" + } + }, + "type": "pullrequest", + "description": "Test", + "links": { + "decline": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/decline" + }, + "diffstat": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/diffstat/rutvijmehta-harness/spring-cloud-alibaba:b9437f32dddd%0Dcfd2d864e389?from_pullrequest_id=1&topic=true" + }, + "commits": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/commits" + }, + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1" + }, + "comments": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/comments" + }, + "merge": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/merge" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1" + }, + "activity": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/activity" + }, + "request-changes": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/request-changes" + }, + "diff": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/diff/rutvijmehta-harness/spring-cloud-alibaba:b9437f32dddd%0Dcfd2d864e389?from_pullrequest_id=1&topic=true" + }, + "approve": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/approve" + }, + "statuses": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/statuses" + } + }, + "title": "Update pom.xml", + "close_source_branch": false, + "reviewers": [], + "id": 1, + "destination": { + "commit": { + "hash": "cfd2d864e389", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/commit/cfd2d864e389" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/commits/cfd2d864e389" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "type": "repository", + "name": "spring-cloud-alibaba", + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}" + }, + "branch": { + "name": "2021.x" + } + }, + "created_on": "2022-06-23T19:27:25.443049+00:00", + "summary": { + "raw": "Test", + "markup": "markdown", + "html": "

Test

", + "type": "rendered" + }, + "source": { + "commit": { + "hash": "b9437f32dddd", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/commit/b9437f32dddd" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/commits/b9437f32dddd" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "type": "repository", + "name": "spring-cloud-alibaba", + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}" + }, + "branch": { + "name": "tiwhitepaper-rutvij" + } + }, + "comment_count": 1, + "state": "OPEN", + "task_count": 0, + "participants": [ + { + "participated_on": "2022-06-23T22:10:09.939978+00:00", + "state": null, + "role": "PARTICIPANT", + "user": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "type": "participant", + "approved": false + } + ], + "reason": "", + "updated_on": "2022-06-23T22:10:09.939978+00:00", + "author": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "merge_commit": null, + "closed_by": null + }, + "repository": { + "scm": "git", + "website": null, + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "project": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/workspaces/rutvijmehta-harness/projects/TEST" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/workspace/projects/TEST" + }, + "avatar": { + "href": "https://bitbucket.org/account/user/rutvijmehta-harness/projects/TEST/avatar/32?ts=1655023274" + } + }, + "type": "project", + "name": "Test", + "key": "TEST", + "uuid": "{aa857cae-daad-4fbd-93ef-503cc3d6c3d6}" + }, + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "owner": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "workspace": { + "slug": "rutvijmehta-harness", + "type": "workspace", + "name": "Rutvij Mehta", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/workspaces/rutvijmehta-harness" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/" + }, + "avatar": { + "href": "https://bitbucket.org/workspaces/rutvijmehta-harness/avatar/?ts=1655023237" + } + }, + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}" + }, + "type": "repository", + "is_private": false, + "name": "spring-cloud-alibaba" + }, + "actor": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + } +} \ No newline at end of file diff --git a/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json.golden b/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json.golden new file mode 100644 index 000000000..f4b06fb9d --- /dev/null +++ b/scm/driver/bitbucket/testdata/webhooks/pr_comment_created.json.golden @@ -0,0 +1,96 @@ +{ + "Action": "created", + "Repo": { + "ID": "{4402cbae-7790-453a-b29e-5fcab61a84df}", + "Namespace": "rutvijmehta-harness", + "Name": "spring-cloud-alibaba", + "Perm": null, + "Branch": "", + "Archived": false, + "Private": false, + "Visibility": 0, + "Clone": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba.git", + "CloneSSH": "git@bitbucket.org:rutvijmehta-harness/spring-cloud-alibaba.git", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Issue": { + "Number": 1, + "Title": "Update pom.xml", + "Body": "Test", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1", + "Labels": null, + "Closed": false, + "Locked": false, + "Author": { + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "PullRequest": { + "Number": 1, + "Title": "Update pom.xml", + "Body": "Test", + "Sha": "b9437f32dddd", + "Ref": "refs/pull-requests/1/from", + "Source": "tiwhitepaper-rutvij", + "Target": "2021.x", + "Fork": "rutvijmehta-harness/spring-cloud-alibaba", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1", + "Diff": "", + "Closed": false, + "Merged": false, + "Base": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Head": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Author": { + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2022-06-23T19:27:25.443049Z", + "Updated": "2022-06-23T22:10:09.939978Z", + "Labels": null + }, + "Created": "2022-06-23T19:27:25.443049Z", + "Updated": "2022-06-23T22:10:09.939978Z" + }, + "Comment": { + "ID": 311512047, + "Body": "test comment", + "Author": { + "ID": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2022-06-23T22:10:09.939925Z", + "Updated": "2022-06-23T22:10:09.939978Z" + }, + "Sender": { + "ID": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + } +} \ No newline at end of file diff --git a/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json b/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json new file mode 100644 index 000000000..23b3f0e3b --- /dev/null +++ b/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json @@ -0,0 +1,305 @@ +{ + "comment": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/comments/311512047" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1/_/diff#comment-311512047" + } + }, + "deleted": true, + "pullrequest": { + "type": "pullrequest", + "id": 1, + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1" + } + }, + "title": "Update pom.xml" + }, + "content": { + "raw": "", + "markup": "markdown", + "html": "", + "type": "rendered" + }, + "created_on": "2022-06-23T22:10:09.939925+00:00", + "user": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "updated_on": "2022-06-24T01:38:47.831843+00:00", + "type": "pullrequest_comment", + "id": 311512047 + }, + "pullrequest": { + "rendered": { + "description": { + "raw": "Test", + "markup": "markdown", + "html": "

Test

", + "type": "rendered" + }, + "title": { + "raw": "Update pom.xml", + "markup": "markdown", + "html": "

Update pom.xml

", + "type": "rendered" + } + }, + "type": "pullrequest", + "description": "Test", + "links": { + "decline": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/decline" + }, + "diffstat": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/diffstat/rutvijmehta-harness/spring-cloud-alibaba:b9437f32dddd%0Dcfd2d864e389?from_pullrequest_id=1&topic=true" + }, + "commits": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/commits" + }, + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1" + }, + "comments": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/comments" + }, + "merge": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/merge" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1" + }, + "activity": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/activity" + }, + "request-changes": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/request-changes" + }, + "diff": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/diff/rutvijmehta-harness/spring-cloud-alibaba:b9437f32dddd%0Dcfd2d864e389?from_pullrequest_id=1&topic=true" + }, + "approve": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/approve" + }, + "statuses": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/pullrequests/1/statuses" + } + }, + "title": "Update pom.xml", + "close_source_branch": false, + "reviewers": [], + "id": 1, + "destination": { + "commit": { + "hash": "cfd2d864e389", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/commit/cfd2d864e389" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/commits/cfd2d864e389" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "type": "repository", + "name": "spring-cloud-alibaba", + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}" + }, + "branch": { + "name": "2021.x" + } + }, + "created_on": "2022-06-23T19:27:25.443049+00:00", + "summary": { + "raw": "Test", + "markup": "markdown", + "html": "

Test

", + "type": "rendered" + }, + "source": { + "commit": { + "hash": "b9437f32dddd", + "type": "commit", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba/commit/b9437f32dddd" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/commits/b9437f32dddd" + } + } + }, + "repository": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "type": "repository", + "name": "spring-cloud-alibaba", + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}" + }, + "branch": { + "name": "tiwhitepaper-rutvij" + } + }, + "comment_count": 0, + "state": "OPEN", + "task_count": 0, + "participants": [], + "reason": "", + "updated_on": "2022-06-24T01:40:18.667126+00:00", + "author": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "merge_commit": null, + "closed_by": null + }, + "repository": { + "scm": "git", + "website": null, + "uuid": "{4402cbae-7790-453a-b29e-5fcab61a84df}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/repositories/rutvijmehta-harness/spring-cloud-alibaba" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba" + }, + "avatar": { + "href": "https://bytebucket.org/ravatar/%7B4402cbae-7790-453a-b29e-5fcab61a84df%7D?ts=default" + } + }, + "project": { + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/workspaces/rutvijmehta-harness/projects/TEST" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/workspace/projects/TEST" + }, + "avatar": { + "href": "https://bitbucket.org/account/user/rutvijmehta-harness/projects/TEST/avatar/32?ts=1655023274" + } + }, + "type": "project", + "name": "Test", + "key": "TEST", + "uuid": "{aa857cae-daad-4fbd-93ef-503cc3d6c3d6}" + }, + "full_name": "rutvijmehta-harness/spring-cloud-alibaba", + "owner": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + }, + "workspace": { + "slug": "rutvijmehta-harness", + "type": "workspace", + "name": "Rutvij Mehta", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/workspaces/rutvijmehta-harness" + }, + "html": { + "href": "https://bitbucket.org/rutvijmehta-harness/" + }, + "avatar": { + "href": "https://bitbucket.org/workspaces/rutvijmehta-harness/avatar/?ts=1655023237" + } + }, + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}" + }, + "type": "repository", + "is_private": false, + "name": "spring-cloud-alibaba" + }, + "actor": { + "display_name": "Rutvij Mehta", + "uuid": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "links": { + "self": { + "href": "https://api.bitbucket.org/2.0/users/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D" + }, + "html": { + "href": "https://bitbucket.org/%7B145a94da-035e-42d6-bf85-296cea8005ba%7D/" + }, + "avatar": { + "href": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png" + } + }, + "type": "user", + "nickname": "Rutvij Mehta", + "account_id": "624de6f6fd5e450070486936" + } +} \ No newline at end of file diff --git a/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json.golden b/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json.golden new file mode 100644 index 000000000..7190b1ff7 --- /dev/null +++ b/scm/driver/bitbucket/testdata/webhooks/pr_comment_deleted.json.golden @@ -0,0 +1,96 @@ +{ + "Action": "deleted", + "Repo": { + "ID": "{4402cbae-7790-453a-b29e-5fcab61a84df}", + "Namespace": "rutvijmehta-harness", + "Name": "spring-cloud-alibaba", + "Perm": null, + "Branch": "", + "Archived": false, + "Private": false, + "Visibility": 0, + "Clone": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba.git", + "CloneSSH": "git@bitbucket.org:rutvijmehta-harness/spring-cloud-alibaba.git", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Issue": { + "Number": 1, + "Title": "Update pom.xml", + "Body": "Test", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1", + "Labels": null, + "Closed": false, + "Locked": false, + "Author": { + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "PullRequest": { + "Number": 1, + "Title": "Update pom.xml", + "Body": "Test", + "Sha": "b9437f32dddd", + "Ref": "refs/pull-requests/1/from", + "Source": "tiwhitepaper-rutvij", + "Target": "2021.x", + "Fork": "rutvijmehta-harness/spring-cloud-alibaba", + "Link": "https://bitbucket.org/rutvijmehta-harness/spring-cloud-alibaba/pull-requests/1", + "Diff": "", + "Closed": false, + "Merged": false, + "Base": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Head": { + "Name": "", + "Path": "", + "Sha": "" + }, + "Author": { + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2022-06-23T19:27:25.443049Z", + "Updated": "2022-06-24T01:40:18.667126Z", + "Labels": null + }, + "Created": "2022-06-23T19:27:25.443049Z", + "Updated": "2022-06-24T01:40:18.667126Z" + }, + "Comment": { + "ID": 311512047, + "Body": "", + "Author": { + "ID": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + }, + "Created": "2022-06-23T22:10:09.939925Z", + "Updated": "2022-06-24T01:38:47.831843Z" + }, + "Sender": { + "ID": "{145a94da-035e-42d6-bf85-296cea8005ba}", + "Login": "", + "Name": "Rutvij Mehta", + "Email": "", + "Avatar": "https://secure.gravatar.com/avatar/1bf4d1258f18330b314d2737db430cb0?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FRM-5.png", + "Created": "0001-01-01T00:00:00Z", + "Updated": "0001-01-01T00:00:00Z" + } +} \ No newline at end of file diff --git a/scm/driver/bitbucket/webhook.go b/scm/driver/bitbucket/webhook.go index da62ba876..c567e565f 100644 --- a/scm/driver/bitbucket/webhook.go +++ b/scm/driver/bitbucket/webhook.go @@ -53,6 +53,23 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo if hook != nil { hook.(*scm.PullRequestHook).Action = scm.ActionClose } + case "pullrequest:comment_created": + hook, err = s.parsePullRequestCommentHook(data) + if hook != nil { + hook.(*scm.IssueCommentHook).Action = scm.ActionCreate + } + case "pullrequest:comment_updated": + // Bitbucket PR Comment Update is unreliable and does not send events + // most of the time https://github.com/iterative/cml/issues/817 + hook, err = s.parsePullRequestCommentHook(data) + if hook != nil { + hook.(*scm.IssueCommentHook).Action = scm.ActionEdit + } + case "pullrequest:comment_deleted": + hook, err = s.parsePullRequestCommentHook(data) + if hook != nil { + hook.(*scm.IssueCommentHook).Action = scm.ActionDelete + } } if err != nil { return nil, err @@ -78,6 +95,12 @@ func (s *webhookService) Parse(req *http.Request, fn scm.SecretFunc) (scm.Webhoo return hook, nil } +func (s *webhookService) parsePullRequestCommentHook(data []byte) (scm.Webhook, error) { + dst := new(prCommentHook) + err := json.Unmarshal(data, dst) + return convertPrCommentHook(dst), err +} + func (s *webhookService) parsePushHook(data []byte) (scm.Webhook, error) { dst := new(pushHook) err := json.Unmarshal(data, dst) @@ -381,6 +404,194 @@ type ( } `json:"links"` UUID string `json:"uuid"` } + + prComment struct { + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + } `json:"links"` + Deleted bool `json:"deleted"` + PullRequest struct { + Type string `json:"type"` + ID int `json:"id"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + } `json:"links"` + Title string `json:"title"` + } + Content struct { + Raw string `json:"raw"` + Markup string `json:"markup"` + Html string `json:"html"` + Type string `json:"type"` + } + CreatedOn time.Time `json:"created_on"` + User prCommentHookUser `json:"user"` + UpdatedOn time.Time `json:"updated_on"` + Type string `json:"type"` + ID int `json:"id"` + } + + prCommentHookRepo struct { + Scm string `json:"scm"` + Website string `json:"website"` + UUID string `json:"uuid"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + Project struct { + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + Type string `json:"type"` + Name string `json:"name"` + Key string `json:"key"` + UUID string `json:"uuid"` + } `json:"project"` + FullName string `json:"full_name"` + Owner prCommentHookUser `json:"owner"` + Workspace struct { + Slug string `json:"slugg"` + Type string `json:"type"` + Name string `json:"name"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + UUID string `json:"uuid"` + } `json:"workspace"` + Type string `json:"type"` + IsPrivate bool `json:"is_private"` + Name string `json:"name"` + } + + prCommentHookUser struct { + Username string `json:"username"` + DisplayName string `json:"display_name"` + UUID string `json:"uuid"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + Type string `json:"type"` + Nickname string `json:"nickname"` + AccountID string `json:"account_id"` + } + + prCommentHookPullRequest struct { + Rendered struct { + Description struct { + Raw string `json:"raw"` + Markup string `json:"markup"` + Html string `json:"html"` + Type string `json:"type"` + } `json:"description"` + Title struct { + Raw string `json:"raw"` + Markup string `json:"markup"` + Html string `json:"html"` + Type string `json:"type"` + } `json:"title"` + } `json:"rendered"` + Type string `json:"type"` + Description string `json:"description"` + Links struct { + Decline link `json:"decline"` + Diffstat link `json:"diffstat"` + Commits link `json:"commits"` + Self link `json:"self"` + Comments link `json:"comments"` + Merge link `json:"merge"` + Html link `json:"html"` + Activity link `json:"activity"` + RequestChanges link `json:"request-changes"` + Diff link `json:"diff"` + Approve link `json:"approve"` + Statuses link `json:"statuses"` + } `json:"links"` + Title string `json:"title"` + CloseSourceBranch bool `json:"close_source_branch"` + Reviewers []interface{} `json:"reviewers"` + ID int `json:"id"` + Destination struct { + Commit struct { + Hash string `json:"hash"` + Type string `json:"type"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + } `json:"links"` + } + Repository struct { + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + Type string `json:"type"` + Name string `json:"name"` + FullName string `json:"full_name"` + UUID string `json:"uuid"` + } `json:"repository"` + Branch struct { + Name string `json:"name"` + } `json:"branch"` + } `json:"destination"` + CreatedOn time.Time `json:"created_on"` + Summary struct { + Raw string `json:"raw"` + Markup string `json:"markup"` + Html string `json:"html"` + Type string `json:"type"` + } `json:"summary"` + Source struct { + Commit struct { + Hash string `json:"hash"` + Type string `json:"type"` + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + } `json:"links"` + } + Repository struct { + Links struct { + Self link `json:"self"` + HTML link `json:"html"` + Avatar link `json:"avatar"` + } `json:"links"` + Type string `json:"type"` + Name string `json:"name"` + FullName string `json:"full_name"` + UUID string `json:"uuid"` + } `json:"repository"` + Branch struct { + Name string `json:"name"` + } `json:"branch"` + } `json:"source"` + CommentCount int `json:"comment_count"` + State string `json:"state"` + TaskCount int `json:"task_count"` + Participants []interface{} `json:"participants"` + Reason string `json:"reason"` + UpdatedOn time.Time `json:"updated_on"` + Author prCommentHookUser `json:"author"` + MergeCommit interface{} `json:"merge_commit"` + ClosedBy interface{} `json:"closed_by"` + } + + prCommentHook struct { + Comment prComment `json:"comment"` + PullRequest prCommentHookPullRequest `json:"pullRequest"` + Repository prCommentHookRepo `json:"repository"` + Actor prCommentHookUser `json:"actor"` + } ) // @@ -610,3 +821,71 @@ func convertPullRequestHook(src *webhook) *scm.PullRequestHook { }, } } + +func convertPrCommentHook(src *prCommentHook) *scm.IssueCommentHook { + namespace, _ := scm.Split(src.Repository.FullName) + dst := scm.IssueCommentHook{ + Repo: scm.Repository{ + ID: src.Repository.UUID, + Namespace: namespace, + Name: src.Repository.Name, + Clone: fmt.Sprintf("https://bitbucket.org/%s.git", src.Repository.FullName), + CloneSSH: fmt.Sprintf("git@bitbucket.org:%s.git", src.Repository.FullName), + Link: src.Repository.Links.HTML.Href, + Private: src.Repository.IsPrivate, + }, + Issue: scm.Issue{ + Number: src.PullRequest.ID, + Title: src.PullRequest.Title, + Body: src.PullRequest.Description, + Link: src.PullRequest.Links.Html.Href, + Author: scm.User{ + Login: src.PullRequest.Author.Username, + Name: src.PullRequest.Author.DisplayName, + Avatar: src.PullRequest.Author.Links.Avatar.Href, + }, + PullRequest: scm.PullRequest{ + Number: src.PullRequest.ID, + Title: src.PullRequest.Title, + Body: src.PullRequest.Description, + Sha: src.PullRequest.Source.Commit.Hash, + // Bitbucket does not support PR Refs: https://jira.atlassian.com/browse/BCLOUD-5814 + Ref: fmt.Sprintf("refs/pull-requests/%d/from", src.PullRequest.ID), + Source: src.PullRequest.Source.Branch.Name, + Target: src.PullRequest.Destination.Branch.Name, + Fork: src.PullRequest.Source.Repository.FullName, + Link: src.PullRequest.Links.Html.Href, + Closed: src.PullRequest.State != "OPEN", + Merged: src.PullRequest.State == "MERGED", + Author: scm.User{ + Login: src.PullRequest.Author.Username, + Name: src.PullRequest.Author.DisplayName, + Avatar: src.PullRequest.Author.Links.Avatar.Href, + }, + Created: src.PullRequest.CreatedOn, + Updated: src.PullRequest.UpdatedOn, + }, + Created: src.PullRequest.CreatedOn, + Updated: src.PullRequest.UpdatedOn, + }, + Comment: scm.Comment{ + ID: src.Comment.ID, + Body: src.Comment.Content.Raw, + Author: scm.User{ + ID: src.Comment.User.UUID, + Login: src.Comment.User.Username, + Name: src.Comment.User.DisplayName, + Avatar: src.Comment.User.Links.Avatar.Href, + }, + Created: src.Comment.CreatedOn, + Updated: src.Comment.UpdatedOn, + }, + Sender: scm.User{ + ID: src.Actor.UUID, + Login: src.Actor.Username, + Name: src.Actor.DisplayName, + Avatar: src.Actor.Links.Avatar.Href, + }, + } + return &dst +} diff --git a/scm/driver/bitbucket/webhook_test.go b/scm/driver/bitbucket/webhook_test.go index 9e633ed23..e72e096ff 100644 --- a/scm/driver/bitbucket/webhook_test.go +++ b/scm/driver/bitbucket/webhook_test.go @@ -132,6 +132,20 @@ func TestWebhooks(t *testing.T) { // after: "samples/pr_unlabeled.json.golden", // obj: new(scm.PullRequestHook), // }, + { + sig: "71295b197fa25f4356d2fb9965df3f2379d903d7", + event: "pullrequest:comment_created", + before: "testdata/webhooks/pr_comment_created.json", + after: "testdata/webhooks/pr_comment_created.json.golden", + obj: new(scm.IssueCommentHook), + }, + { + sig: "71295b197fa25f4356d2fb9965df3f2379d903d7", + event: "pullrequest:comment_deleted", + before: "testdata/webhooks/pr_comment_deleted.json", + after: "testdata/webhooks/pr_comment_deleted.json.golden", + obj: new(scm.IssueCommentHook), + }, } for _, test := range tests { diff --git a/scm/user.go b/scm/user.go index e1ea08fa5..fd448770a 100644 --- a/scm/user.go +++ b/scm/user.go @@ -12,6 +12,7 @@ import ( type ( // User represents a user account. User struct { + ID string Login string Name string Email string From 5f245ea841e985bef2cc34c456e73328cd95451c Mon Sep 17 00:00:00 2001 From: Rutvij Mehta Date: Thu, 30 Jun 2022 02:20:00 -0700 Subject: [PATCH 5/5] Update scm version 1.26.0 (#203) --- CHANGELOG.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 642d37d15..8bc4f787f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,23 @@ # Changelog +## [v1.26.0](https://github.com/drone/go-scm/tree/v1.26.0) (2022-07-01) + +[Full Changelog](https://github.com/drone/go-scm/compare/v1.25.0...v1.26.0) + +**Implemented enhancements:** + +- Support parsing PR comment events for Bitbucket Cloud [\#202](https://github.com/drone/go-scm/pull/202) ([rutvijmehta-harness](https://github.com/rutvijmehta-harness)) +- added issue comment hook support for Azure [\#200](https://github.com/drone/go-scm/pull/200) ([raghavharness](https://github.com/raghavharness)) + +**Fixed bugs:** + +- \[CI-4623\] - Azure webhook parseAPI changes [\#198](https://github.com/drone/go-scm/pull/198) ([raghavharness](https://github.com/raghavharness)) + +**Merged pull requests:** + +- Update scm version 1.26.0 [\#203](https://github.com/drone/go-scm/pull/203) ([rutvijmehta-harness](https://github.com/rutvijmehta-harness)) +- Fixed formatting in README.md [\#199](https://github.com/drone/go-scm/pull/199) ([hemanthmantri](https://github.com/hemanthmantri)) + ## [v1.25.0](https://github.com/drone/go-scm/tree/v1.25.0) (2022-06-16) [Full Changelog](https://github.com/drone/go-scm/compare/v1.24.0...v1.25.0) @@ -13,6 +31,10 @@ - \[PL-25889\]: fix list branches Azure API [\#195](https://github.com/drone/go-scm/pull/195) ([bhavya181](https://github.com/bhavya181)) - Return project specific hooks only in ListHooks API for Azure. [\#192](https://github.com/drone/go-scm/pull/192) ([raghavharness](https://github.com/raghavharness)) +**Merged pull requests:** + +- Update scm version 1.25.0 [\#197](https://github.com/drone/go-scm/pull/197) ([rutvijmehta-harness](https://github.com/rutvijmehta-harness)) + ## [v1.24.0](https://github.com/drone/go-scm/tree/v1.24.0) (2022-06-07) [Full Changelog](https://github.com/drone/go-scm/compare/v1.23.0...v1.24.0)