Skip to content

Commit

Permalink
Merge pull request #657 from runatlantis/bbcloud-gdpr
Browse files Browse the repository at this point in the history
Fix require-approval for Bitbucket Cloud.
  • Loading branch information
lkysow authored Jun 3, 2019
2 parents 354551d + 8f81568 commit dd64fcd
Show file tree
Hide file tree
Showing 6 changed files with 350 additions and 142 deletions.
3 changes: 2 additions & 1 deletion server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool
if err := validator.New().Struct(pullResp); err != nil {
return false, errors.Wrapf(err, "API response %q was missing fields", string(resp))
}
authorUUID := *pullResp.Author.UUID
for _, participant := range pullResp.Participants {
// Bitbucket allows the author to approve their own pull request. This
// defeats the purpose of approvals so we don't count that approval.
if *participant.Approved && *participant.User.Username != pull.Author {
if *participant.Approved && *participant.User.UUID != authorUUID {
return true, nil
}
}
Expand Down
7 changes: 6 additions & 1 deletion server/events/vcs/bitbucketcloud/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type PullRequest struct {
Participants []Participant `json:"participants,omitempty" validate:"required"`
Links *Links `json:"links,omitempty" validate:"required"`
State *string `json:"state,omitempty" validate:"required"`
Author *Author `jsonN:"author,omitempty" validate:"required"`
}
type Links struct {
HTML *Link `json:"html,omitempty" validate:"required"`
Expand All @@ -61,7 +62,7 @@ type Link struct {
type Participant struct {
Approved *bool `json:"approved,omitempty" validate:"required"`
User *struct {
Username *string `json:"username,omitempty" validate:"required"`
UUID *string `json:"uuid,omitempty" validate:"required"`
} `json:"user,omitempty" validate:"required"`
}
type BranchMeta struct {
Expand All @@ -86,3 +87,7 @@ type ConflictStatus struct {
MergeImpossible *bool `json:"mergeimpossible,omitempty" validate:"required"`
IsConflicted *bool `json:"isconflicted,omitempty" validate:"required"`
}

type Author struct {
UUID *string `json:"uuid,omitempty" validate:"required"`
}
109 changes: 75 additions & 34 deletions server/events/vcs/bitbucketcloud/testdata/pull-approved-by-author.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,66 @@
{
"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/5/decline"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/decline"
},
"commits": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/commits"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/commits"
},
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12"
},
"comments": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/comments"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/comments"
},
"merge": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/merge"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/merge"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example/pull-requests/5"
"href": "https://bitbucket.org/lkysow/atlantis-example/pull-requests/12"
},
"activity": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/activity"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/activity"
},
"diff": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/diff"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/diff"
},
"approve": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/approve"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/approve"
},
"statuses": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/5/statuses"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/pullrequests/12/statuses"
}
},
"title": "main.tf edited online with Bitbucket",
"close_source_branch": true,
"reviewers": [],
"id": 5,
"id": 12,
"destination": {
"commit": {
"hash": "fe607a7f5172",
"hash": "c641f2c615ad",
"type": "commit",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/fe607a7f5172"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/c641f2c615ad"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example/commits/fe607a7f5172"
"href": "https://bitbucket.org/lkysow/atlantis-example/commits/c641f2c615ad"
}
}
},
Expand All @@ -71,7 +85,7 @@
"name": "master"
}
},
"created_on": "2018-07-25T12:23:21.100810+00:00",
"created_on": "2019-02-12T16:48:04.251028+00:00",
"summary": {
"raw": "main.tf edited online with Bitbucket",
"markup": "markdown",
Expand All @@ -80,14 +94,14 @@
},
"source": {
"commit": {
"hash": "3428957ade18",
"hash": "75d1e7c57cd9",
"type": "commit",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/3428957ade18"
"href": "https://api.bitbucket.org/2.0/repositories/lkysow/atlantis-example/commit/75d1e7c57cd9"
},
"html": {
"href": "https://bitbucket.org/lkysow/atlantis-example/commits/3428957ade18"
"href": "https://bitbucket.org/lkysow/atlantis-example/commits/75d1e7c57cd9"
}
}
},
Expand All @@ -109,58 +123,85 @@
"uuid": "{94189367-116b-436a-9f77-2314b97a6067}"
},
"branch": {
"name": "lkysow/maintf-edited-online-with-bitbucket-1532521398289"
"name": "lkysow/maintf-edited-online-with-bitbucket-1549990080103"
}
},
"comment_count": 3,
"comment_count": 23,
"state": "OPEN",
"task_count": 0,
"participants": [
{
"role": "PARTICIPANT",
"participated_on": "2018-07-28T00:06:42.255492+00:00",
"participated_on": "2019-06-03T13:55:54.065877+00:00",
"type": "participant",
"approved": true,
"user": {
"username": "author",
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}",
"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",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090"
}
},
{
"role": "PARTICIPANT",
"participated_on": "2019-06-03T13:51:47.350675+00:00",
"type": "participant",
"approved": false,
"user": {
"username": "atlantis-bot",
"display_name": "Atlantisbot",
"uuid": "{73686412-4495-426f-89a7-c69ff1c8d7b8}",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
"href": "https://api.bitbucket.org/2.0/users/%7B73686412-4495-426f-89a7-c69ff1c8d7b8%7D"
},
"html": {
"href": "https://bitbucket.org/lkysow/"
"href": "https://bitbucket.org/%7B73686412-4495-426f-89a7-c69ff1c8d7b8%7D/"
},
"avatar": {
"href": "https://bitbucket.org/account/lkysow/avatar/"
"href": "https://avatar-cdn.atlassian.com/5b5097035488b9140c078f7f?by=id&sg=vyisLdHfYH10sFOuFCvPgHKn6ds%3D&d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FA-1.png"
}
},
"nickname": "Atlantisbot",
"type": "user",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}"
"account_id": "5b5097035488b9140c078f7f"
}
}
],
"reason": "",
"updated_on": "2018-07-28T00:06:42.257659+00:00",
"updated_on": "2019-06-03T13:55:54.081581+00:00",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"uuid": "{bf34a99b-8a11-452c-8fbc-bdffc340e584}",
"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}"
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090"
},
"merge_commit": null,
"closed_by": null
}
}
Loading

0 comments on commit dd64fcd

Please sign in to comment.