-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support bitbucket server pr:deleted event
If a pull request is deleted, Atlantis should delete the locks. Fixes #498
- Loading branch information
Showing
7 changed files
with
202 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -524,6 +524,83 @@ func TestPost_GitlabMergeRequestSuccess(t *testing.T) { | |
responseContains(t, w, http.StatusOK, "Pull request cleaned successfully") | ||
} | ||
|
||
// Test Bitbucket server pull closed events. | ||
func TestPost_BBServerPullClosed(t *testing.T) { | ||
cases := []struct { | ||
header string | ||
}{ | ||
{ | ||
"pr:deleted", | ||
}, | ||
{ | ||
"pr:merged", | ||
}, | ||
{ | ||
"pr:declined", | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
t.Run(c.header, func(t *testing.T) { | ||
RegisterMockTestingT(t) | ||
pullCleaner := emocks.NewMockPullCleaner() | ||
whitelist, err := events.NewRepoWhitelistChecker("*") | ||
Ok(t, err) | ||
ec := &server.EventsController{ | ||
PullCleaner: pullCleaner, | ||
Parser: &events.EventParser{ | ||
BitbucketUser: "bb-user", | ||
BitbucketToken: "bb-token", | ||
BitbucketServerURL: "https://bbserver.com", | ||
}, | ||
RepoWhitelistChecker: whitelist, | ||
SupportedVCSHosts: []models.VCSHostType{models.BitbucketServer}, | ||
VCSClient: nil, | ||
} | ||
|
||
// Build HTTP request. | ||
requestBytes, err := ioutil.ReadFile(filepath.Join("testfixtures", "bb-server-pull-deleted-event.json")) | ||
// Replace the eventKey field with our event type. | ||
requestJSON := strings.Replace(string(requestBytes), `"eventKey":"pr:deleted",`, fmt.Sprintf(`"eventKey":"%s",`, c.header), -1) | ||
Ok(t, err) | ||
req, err := http.NewRequest("POST", "/events", bytes.NewBuffer([]byte(requestJSON))) | ||
Ok(t, err) | ||
req.Header.Set("Content-Type", "application/json") | ||
req.Header.Set("X-Event-Key", c.header) | ||
req.Header.Set("X-Request-ID", "request-id") | ||
|
||
// Send the request. | ||
w := httptest.NewRecorder() | ||
ec.Post(w, req) | ||
|
||
// Make our assertions. | ||
responseContains(t, w, 200, "Pull request cleaned successfully") | ||
|
||
expRepo := models.Repo{ | ||
FullName: "project/repository", | ||
Owner: "project", | ||
Name: "repository", | ||
CloneURL: "https://bb-user:[email protected]/scm/proj/repository.git", | ||
SanitizedCloneURL: "https://bbserver.com/scm/proj/repository.git", | ||
VCSHost: models.VCSHost{ | ||
Hostname: "bbserver.com", | ||
Type: models.BitbucketServer, | ||
}, | ||
} | ||
pullCleaner.VerifyWasCalledOnce().CleanUpPull(expRepo, models.PullRequest{ | ||
Num: 10, | ||
HeadCommit: "2d9fb6b9a46eafb1dcef7b008d1a429d45ca742c", | ||
URL: "https://bbserver.com/projects/PROJ/repos/repository/pull-requests/10", | ||
HeadBranch: "decline-me", | ||
BaseBranch: "master", | ||
Author: "admin", | ||
State: models.OpenPullState, | ||
BaseRepo: expRepo, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func TestPost_PullOpenedOrUpdated(t *testing.T) { | ||
cases := []struct { | ||
Description string | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
{ | ||
"eventKey":"pr:deleted", | ||
"date":"2017-09-19T11:16:17+1000", | ||
"actor":{ | ||
"name":"admin", | ||
"emailAddress":"[email protected]", | ||
"id":1, | ||
"displayName":"Administrator", | ||
"active":true, | ||
"slug":"admin", | ||
"type":"NORMAL" | ||
}, | ||
"pullRequest":{ | ||
"id":10, | ||
"version":3, | ||
"title":"Commit message", | ||
"state":"OPEN", | ||
"open":true, | ||
"closed":false, | ||
"createdDate":1505783668760, | ||
"updatedDate":1505783750704, | ||
"fromRef":{ | ||
"id":"refs/heads/decline-me", | ||
"displayId":"decline-me", | ||
"latestCommit":"2d9fb6b9a46eafb1dcef7b008d1a429d45ca742c", | ||
"repository":{ | ||
"slug":"repository", | ||
"id":84, | ||
"name":"repository", | ||
"scmId":"git", | ||
"state":"AVAILABLE", | ||
"statusMessage":"Available", | ||
"forkable":true, | ||
"project":{ | ||
"key":"PROJ", | ||
"id":84, | ||
"name":"project", | ||
"public":false, | ||
"type":"NORMAL" | ||
}, | ||
"public":false | ||
} | ||
}, | ||
"toRef":{ | ||
"id":"refs/heads/master", | ||
"displayId":"master", | ||
"latestCommit":"7e48f426f0a6e47c5b5e862c31be6ca965f82c9c", | ||
"repository":{ | ||
"slug":"repository", | ||
"id":84, | ||
"name":"repository", | ||
"scmId":"git", | ||
"state":"AVAILABLE", | ||
"statusMessage":"Available", | ||
"forkable":true, | ||
"project":{ | ||
"key":"PROJ", | ||
"id":84, | ||
"name":"project", | ||
"public":false, | ||
"type":"NORMAL" | ||
}, | ||
"public":false | ||
} | ||
}, | ||
"locked":false, | ||
"author":{ | ||
"user":{ | ||
"name":"admin", | ||
"emailAddress":"[email protected]", | ||
"id":1, | ||
"displayName":"Administrator", | ||
"active":true, | ||
"slug":"admin", | ||
"type":"NORMAL" | ||
}, | ||
"role":"AUTHOR", | ||
"approved":false, | ||
"status":"UNAPPROVED" | ||
}, | ||
"reviewers":[ | ||
{ | ||
"user":{ | ||
"name":"user", | ||
"emailAddress":"[email protected]", | ||
"id":2, | ||
"displayName":"User", | ||
"active":true, | ||
"slug":"user", | ||
"type":"NORMAL" | ||
}, | ||
"role":"REVIEWER", | ||
"approved":false, | ||
"status":"UNAPPROVED" | ||
} | ||
], | ||
"participants":[ | ||
|
||
] | ||
} | ||
} |