Skip to content

Commit

Permalink
Adding GetIsDeleted() check to Azure DevOps Event Handler (#2838)
Browse files Browse the repository at this point in the history
* Adding GetIsDeleted

* Adding test to see if ADO sucessfully passes all ignore statements

* Changing Ignore Passing test to use matcher

* Changing to use setup method
  • Loading branch information
SSKLCP authored Dec 22, 2022
1 parent b78c4e8 commit 01ce8ce
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/controllers/events/events_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ func (e *VCSEventsController) HandleAzureDevopsPullRequestCommentedEvent(w http.
return
}

if *resource.Comment.IsDeleted {
if resource.Comment.GetIsDeleted() {
e.respond(w, logging.Debug, http.StatusOK, "Ignoring comment event since it is linked to deleting a pull request comment; %s", azuredevopsReqID)
return
}
Expand Down
39 changes: 39 additions & 0 deletions server/controllers/events/events_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,45 @@ func TestPost_AzureDevopsPullRequestDeletedCommentIgnoreEvent(t *testing.T) {
})
}

func TestPost_AzureDevopsPullRequestCommentPassingIgnores(t *testing.T) {
t.Log("when the event should not be ignored it should pass through all ignore statements without error")
e, _, _, ado, _, _, _, _, _ := setup(t)

repo := models.Repo{}
When(e.Parser.ParseAzureDevopsRepo(matchers.AnyPtrToAzuredevopsGitRepository())).ThenReturn(repo, nil)

payload := `{
"subscriptionId": "11111111-1111-1111-1111-111111111111",
"notificationId": 1,
"id": "22222222-2222-2222-2222-222222222222",
"eventType": "ms.vss-code.git-pullrequest-comment-event",
"publisherId": "tfs",
"message": {
"text": "Testing to see if comment passes ignore conditions"
},
"resource": {
"comment": {
"id": 1,
"commentType": "text",
"content": "test"
},
"pullRequest": {
"pullRequestId": 1,
"repository": {}
}
}
}`

t.Run("Testing to see if comment passes ignore conditions", func(t *testing.T) {
req, _ := http.NewRequest("GET", "", strings.NewReader(payload))
req.Header.Set(azuredevopsHeader, "reqID")
When(ado.Validate(req, user, secret)).ThenReturn([]byte(payload), nil)
w := httptest.NewRecorder()
e.Post(w, req)
ResponseContains(t, w, http.StatusOK, "Processing...")
})
}

func TestPost_GithubPullRequestClosedErrCleaningPull(t *testing.T) {
t.Skip("relies too much on mocks, should use real event parser")
t.Log("when the event is a closed pull request and we have an error calling CleanUpPull we return a 503")
Expand Down

0 comments on commit 01ce8ce

Please sign in to comment.