Skip to content

Commit

Permalink
Merge pull request #677 from runatlantis/bb-cloud-rejected
Browse files Browse the repository at this point in the history
Fix bug parsing BB Cloud pull rejected events
  • Loading branch information
lkysow authored Jun 13, 2019
2 parents 47b5512 + a2349b6 commit 26c7df1
Show file tree
Hide file tree
Showing 5 changed files with 351 additions and 254 deletions.
2 changes: 1 addition & 1 deletion server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (e *EventParser) parseCommonBitbucketCloudEventData(event bitbucketcloud.Co
prState = models.ClosedPullState
case "SUPERSEDED":
prState = models.ClosedPullState
case "DECLINE":
case "DECLINED":
prState = models.ClosedPullState
default:
err = fmt.Errorf("unable to determine pull request state from %q–this is a bug", *event.PullRequest.State)
Expand Down
47 changes: 38 additions & 9 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ func TestParseBitbucketCloudCommentEvent_MultipleStates(t *testing.T) {
models.ClosedPullState,
},
{
"DECLINE",
"DECLINED",
models.ClosedPullState,
},
}
Expand All @@ -781,7 +781,7 @@ func TestParseBitbucketCloudCommentEvent_MultipleStates(t *testing.T) {
}

func TestParseBitbucketCloudPullEvent_ValidEvent(t *testing.T) {
path := filepath.Join("testdata", "bitbucket-cloud-pull-event-fulfilled.json")
path := filepath.Join("testdata", "bitbucket-cloud-pull-event-created.json")
bytes, err := ioutil.ReadFile(path)
if err != nil {
Ok(t, err)
Expand All @@ -801,13 +801,13 @@ func TestParseBitbucketCloudPullEvent_ValidEvent(t *testing.T) {
}
Equals(t, expBaseRepo, baseRepo)
Equals(t, models.PullRequest{
Num: 2,
HeadCommit: "e0624da46d3a",
URL: "https://bitbucket.org/lkysow/atlantis-example/pull-requests/2",
HeadBranch: "lkysow/maintf-edited-online-with-bitbucket-1532029690581",
Num: 16,
HeadCommit: "1e69a602caef",
URL: "https://bitbucket.org/lkysow/atlantis-example/pull-requests/16",
HeadBranch: "Luke/maintf-edited-online-with-bitbucket-1560433073473",
BaseBranch: "master",
Author: "lkysow",
State: models.ClosedPullState,
Author: "Luke",
State: models.OpenPullState,
BaseRepo: expBaseRepo,
}, pull)
Equals(t, models.Repo{
Expand All @@ -822,10 +822,39 @@ func TestParseBitbucketCloudPullEvent_ValidEvent(t *testing.T) {
},
}, headRepo)
Equals(t, models.User{
Username: "lkysow",
Username: "Luke",
}, user)
}

func TestParseBitbucketCloudPullEvent_States(t *testing.T) {
for _, c := range []struct {
JSON string
ExpState models.PullRequestState
}{
{
JSON: "bitbucket-cloud-pull-event-created.json",
ExpState: models.OpenPullState,
},
{
JSON: "bitbucket-cloud-pull-event-fulfilled.json",
ExpState: models.ClosedPullState,
},
{
JSON: "bitbucket-cloud-pull-event-rejected.json",
ExpState: models.ClosedPullState,
},
} {
path := filepath.Join("testdata", c.JSON)
bytes, err := ioutil.ReadFile(path)
if err != nil {
Ok(t, err)
}
pull, _, _, _, err := parser.ParseBitbucketCloudPullEvent(bytes)
Ok(t, err)
Equals(t, c.ExpState, pull.State)
}
}

func TestGetBitbucketCloudEventType(t *testing.T) {
cases := []struct {
header string
Expand Down
148 changes: 85 additions & 63 deletions server/events/testdata/bitbucket-cloud-pull-event-created.json
Original file line number Diff line number Diff line change
@@ -1,59 +1,71 @@
{
"pullrequest": {
"rendered": {
"description": {
"raw": "main.tf edited online with Bitbucket",
"markup": "markdown",
"html": "<p>main.tf edited online with Bitbucket</p>",
"type": "rendered"
},
"title": {
"raw": "main.tf edited online with Bitbucket",
"markup": "markdown",
"html": "<p>main.tf edited online with Bitbucket</p>",
"type": "rendered"
}
},
"type": "pullrequest",
"description": "main.tf edited online with Bitbucket",
"links": {
"decline": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/decline"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/decline"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/commits"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/commits"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16"
},
"comments": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/comments"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/comments"
},
"merge": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/merge"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/merge"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example/pull-requests/2"
"href": "https://bitbucket.org/lkysow/atlantis-example/pull-requests/16"
},
"activity": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/activity"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/activity"
},
"diff": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/diff"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/diff"
},
"approve": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/approve"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/approve"
},
"statuses": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/2/statuses"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/16/statuses"
}
},
"title": "main.tf edited online with Bitbucket",
"close_source_branch": true,
"reviewers": [],
"id": 2,
"id": 16,
"destination": {
"commit": {
"hash": "1ed8205eec00",
"hash": "1d1f6d3216f1",
"type": "commit",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/1ed8205eec00"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/1d1f6d3216f1"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example/commits/1d1f6d3216f1"
}
}
},
"branch": {
"name": "master"
},
"repository": {
"full_name": "lkysow/atlantis-example",
"type": "repository",
"name": "atlantis-example",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example"
Expand All @@ -65,10 +77,16 @@
"href": "https://bytebucket.org/ravatar/%7B94189367-116b-436a-9f77-2314b97a6067%7D?ts=default"
}
},
"type": "repository",
"name": "atlantis-example",
"full_name": "lkysow/atlantis-example",
"uuid": "{94189367-116b-436a-9f77-2314b97a6067}"
},
"branch": {
"name": "master"
}
},
"comment_count": 0,
"created_on": "2019-06-13T13:37:58.036928+00:00",
"summary": {
"raw": "main.tf edited online with Bitbucket",
"markup": "markdown",
Expand All @@ -77,78 +95,64 @@
},
"source": {
"commit": {
"hash": "e0624da46d3a",
"hash": "1e69a602caef",
"type": "commit",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/e0624da46d3a"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow-fork/atlantis-example/commit/1e69a602caef"
},
"html": {
"href": "https://bitbucket.org/lkysow-fork/atlantis-example/commits/1e69a602caef"
}
}
},
"branch": {
"name": "lkysow/maintf-edited-online-with-bitbucket-1532029690581"
},
"repository": {
"full_name": "lkysow/atlantis-example",
"type": "repository",
"name": "atlantis-example",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow-fork/atlantis-example"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example"
"href": "https://bitbucket.org/lkysow-fork/atlantis-example"
},
"avatar": {
"href": "https://bytebucket.org/ravatar/%7B94189367-116b-436a-9f77-2314b97a6067%7D?ts=default"
}
},
"type": "repository",
"name": "atlantis-example",
"full_name": "lkysow-fork/atlantis-example",
"uuid": "{94189367-116b-436a-9f77-2314b97a6067}"
},
"branch": {
"name": "Luke/maintf-edited-online-with-bitbucket-1560433073473"
}
},
"comment_count": 0,
"state": "OPEN",
"task_count": 0,
"participants": [],
"reason": "",
"updated_on": "2019-06-13T13:37:58.128400+00:00",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
"href": "https://api.bitbucket.org/2.0/users/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D"
},
"html": {
"href": "https://bitbucket.org/lkysow/"
"href": "https://bitbucket.org/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D/"
},
"avatar": {
"href": "https://bitbucket.org/account/lkysow/avatar/"
"href": "https://avatar-cdn.atlassian.com/557058%3Adc3817de-68b5-45cd-b81c-5c39d2560090?by=id&sg=TUDovBcAEFksW8FiPnLjf1IV73Y%3D&d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FL-1.svg"
}
},
"nickname": "Luke",
"type": "user",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}"
},
"created_on": "2018-07-19T19:48:14.228611+00:00",
"participants": [],
"reason": "",
"updated_on": "2018-07-19T19:48:14.283739+00:00",
"merge_commit": null,
"closed_by": null,
"task_count": 0
},
"actor": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
},
"html": {
"href": "https://bitbucket.org/lkysow/"
},
"avatar": {
"href": "https://bitbucket.org/account/lkysow/avatar/"
}
},
"type": "user",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}"
"closed_by": null
},
"repository": {
"scm": "git",
Expand All @@ -167,25 +171,43 @@
},
"full_name": "lkysow/atlantis-example",
"owner": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
"href": "https://api.bitbucket.org/2.0/users/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D"
},
"html": {
"href": "https://bitbucket.org/lkysow/"
"href": "https://bitbucket.org/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D/"
},
"avatar": {
"href": "https://bitbucket.org/account/lkysow/avatar/"
"href": "https://avatar-cdn.atlassian.com/557058%3Adc3817de-68b5-45cd-b81c-5c39d2560090?by=id&sg=TUDovBcAEFksW8FiPnLjf1IV73Y%3D&d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FL-1.svg"
}
},
"nickname": "Luke",
"type": "user",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}"
},
"type": "repository",
"is_private": false,
"uuid": "{94189367-116b-436a-9f77-2314b97a6067}"
},
"actor": {
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D"
},
"html": {
"href": "https://bitbucket.org/%7Bbf34a99b-8a11-452c-8fbc-bdffc340e584%7D/"
},
"avatar": {
"href": "https://avatar-cdn.atlassian.com/557058%3Adc3817de-68b5-45cd-b81c-5c39d2560090?by=id&sg=TUDovBcAEFksW8FiPnLjf1IV73Y%3D&d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FL-1.svg"
}
},
"nickname": "Luke",
"type": "user",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}"
}
}
}
Loading

0 comments on commit 26c7df1

Please sign in to comment.