Skip to content

added issue comment hook support for Azure #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scm/const.go
Original file line number Diff line number Diff line change
@@ -67,6 +67,8 @@ func (a Action) String() (s string) {
return "synchronized"
case ActionMerge:
return "merged"
case ActionEdit:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not really as update and edit are synonyms

case ActionUpdate:
		return "updated"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tphoney We can't keep this as Update since in triggers we have already defined an edit action on UI. We just checked since ActionEdit was not being passed Github IssueComment trigger with Edit action was not triggering so we need to pass this value. You can check below snippet.

case "edited":

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bradrydzewski how do you feel about adding this new action, it does seem to be referenced in some of the drivers.

Copy link
Member

@bradrydzewski bradrydzewski Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this refers to updating pull request code we should use the synchronized action (which is the abstracted term we use for all providers) or if this refers to updating pull request metadata (tltle, description, status, etc) we should use the update action.

See some of the existing implementations for prior art:
https://github.com/drone/go-scm/blob/master/scm/driver/github/webhook.go#L159:L160

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
}
132 changes: 132 additions & 0 deletions scm/driver/azure/testdata/webhooks/issue_comment.json
Original file line number Diff line number Diff line change
@@ -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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> 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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> a pull request comment<p>This is my comment.</p>",
"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": "[email protected]",
"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": "[email protected]: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": "[email protected]",
"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"
}
88 changes: 88 additions & 0 deletions scm/driver/azure/testdata/webhooks/issue_comment.json.golden
Original file line number Diff line number Diff line change
@@ -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": "[email protected]: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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"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": "[email protected]",
"Created": "0001-01-01T00:00:00Z",
"Updated": "0001-01-01T00:00:00Z"
}
}
133 changes: 133 additions & 0 deletions scm/driver/azure/testdata/webhooks/issue_comment_delete.json
Original file line number Diff line number Diff line change
@@ -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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> 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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> a pull request comment<p>This is my comment.</p>",
"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": "[email protected]",
"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": "[email protected]: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": "[email protected]",
"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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
132 changes: 132 additions & 0 deletions scm/driver/azure/testdata/webhooks/issue_comment_edit.json
Original file line number Diff line number Diff line change
@@ -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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> 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 <a href=\"https://fabrikam.visualstudio.com/DefaultCollection/_git/Fabrikam/pullrequest/1?discussionId=5\">edited</a> a pull request comment<p>This is my comment.</p>",
"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"
}
88 changes: 88 additions & 0 deletions scm/driver/azure/testdata/webhooks/issue_comment_edit.json.golden
Original file line number Diff line number Diff line change
@@ -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"
}
}
192 changes: 192 additions & 0 deletions scm/driver/azure/webhook.go
Original file line number Diff line number Diff line change
@@ -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"`
}
18 changes: 18 additions & 0 deletions scm/driver/azure/webhook_test.go
Original file line number Diff line number Diff line change
@@ -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 {