Skip to content
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

Trying to fix #652 , Bitbucket Cloud GDPR Changes #654

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions server/events/event_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ func (e *EventParser) parseCommonBitbucketCloudEventData(event bitbucketcloud.Co
HeadBranch: *event.PullRequest.Source.Branch.Name,
BaseBranch: *event.PullRequest.Destination.Branch.Name,
Author: *event.Actor.Nickname,
AuthorID: *event.Actor.AccountID,
State: prState,
BaseRepo: baseRepo,
}
Expand Down
4 changes: 4 additions & 0 deletions server/events/event_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ func TestParseBitbucketCloudCommentEvent_ValidEvent(t *testing.T) {
HeadBranch: "lkysow/maintf-edited-online-with-bitbucket-1532029690581",
BaseBranch: "master",
Author: "lkysow",
AuthorID: "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
State: models.ClosedPullState,
BaseRepo: expBaseRepo,
}, pull)
Expand Down Expand Up @@ -807,6 +808,7 @@ func TestParseBitbucketCloudPullEvent_ValidEvent(t *testing.T) {
HeadBranch: "lkysow/maintf-edited-online-with-bitbucket-1532029690581",
BaseBranch: "master",
Author: "lkysow",
AuthorID: "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
State: models.ClosedPullState,
BaseRepo: expBaseRepo,
}, pull)
Expand Down Expand Up @@ -908,6 +910,7 @@ func TestParseBitbucketServerCommentEvent_ValidEvent(t *testing.T) {
HeadBranch: "branch",
BaseBranch: "master",
Author: "lkysow",
AuthorID: "",
State: models.OpenPullState,
BaseRepo: expBaseRepo,
}, pull)
Expand Down Expand Up @@ -990,6 +993,7 @@ func TestParseBitbucketServerPullEvent_ValidEvent(t *testing.T) {
HeadBranch: "branch",
BaseBranch: "master",
Author: "lkysow",
AuthorID: "",
State: models.ClosedPullState,
BaseRepo: expBaseRepo,
}, pull)
Expand Down
2 changes: 2 additions & 0 deletions server/events/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ type PullRequest struct {
BaseBranch string
// Author is the username of the pull request author.
Author string
// Author id is the account_id of the pull request author.
AuthorID string
// State will be one of Open or Closed.
// Gitlab supports an additional "merged" state but Github doesn't so we map
// merged to Closed.
Expand Down
6 changes: 0 additions & 6 deletions server/events/testdata/bitbucket-cloud-comment-event.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
},
"created_on": "2018-07-19T19:51:50.607374+00:00",
"user": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down Expand Up @@ -159,7 +158,6 @@
},
"state": "MERGED",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand All @@ -181,7 +179,6 @@
{
"type": "participant",
"user": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down Expand Up @@ -214,7 +211,6 @@
}
},
"closed_by": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand All @@ -234,7 +230,6 @@
"task_count": 0
},
"actor": {
"username": "lkysow",
"nickname": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
Expand Down Expand Up @@ -269,7 +264,6 @@
},
"full_name": "lkysow/atlantis-example",
"owner": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
},
"state": "MERGED",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand All @@ -129,7 +128,6 @@
{
"type": "participant",
"user": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down Expand Up @@ -162,7 +160,6 @@
}
},
"closed_by": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand All @@ -182,7 +179,6 @@
"task_count": 0
},
"actor": {
"username": "lkysow",
"nickname": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
Expand Down Expand Up @@ -217,7 +213,6 @@
},
"full_name": "lkysow/atlantis-example",
"owner": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/bitbucketcloud/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (b *Client) PullIsApproved(repo models.Repo, pull models.PullRequest) (bool
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.AccountID != pull.AuthorID {
return true, nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/events/vcs/bitbucketcloud/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func TestClient_PullIsApproved(t *testing.T) {
approved, err := client.PullIsApproved(repo, models.PullRequest{
Num: 1,
HeadBranch: "branch",
Author: "author",
AuthorID: "557058:dc3817de-8888-45cd-b81c-5c39d2560090",
BaseRepo: repo,
})
Ok(t, err)
Expand Down
6 changes: 4 additions & 2 deletions server/events/vcs/bitbucketcloud/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type DiffStatFile struct {
}

type Actor struct {
Nickname *string `json:"nickname,omitempty" validate:"required"`
Nickname *string `json:"nickname,omitempty" validate:"required"`
AccountID *string `json:"account_id,omitempty" validate:"required"`
}
type Repository struct {
FullName *string `json:"full_name,omitempty" validate:"required"`
Expand All @@ -61,7 +62,8 @@ type Link struct {
type Participant struct {
Approved *bool `json:"approved,omitempty" validate:"required"`
User *struct {
Username *string `json:"username,omitempty" validate:"required"`
Username *string `json:"username,omitempty" validate:"required"`
AccountID *string `json:"account_id,omitempty" validate:"required"`
} `json:"user,omitempty" validate:"required"`
}
type BranchMeta struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@
"type": "participant",
"approved": true,
"user": {
"username": "author",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"account_id": "557058:dc3817de-8888-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
Expand All @@ -144,7 +143,6 @@
"reason": "",
"updated_on": "2018-07-28T00:06:42.257659+00:00",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@
"type": "participant",
"approved": true,
"user": {
"username": "author",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"account_id": "557058:dc3817de-8888-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
Expand All @@ -146,9 +145,8 @@
"type": "participant",
"approved": true,
"user": {
"username": "approver",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"account_id": "557058:dc3817de-7777-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
Expand All @@ -168,7 +166,6 @@
"reason": "",
"updated_on": "2018-07-28T00:06:42.257659+00:00",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down
4 changes: 1 addition & 3 deletions server/events/vcs/bitbucketcloud/testdata/pull-approved.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@
"type": "participant",
"approved": true,
"user": {
"username": "approver",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"account_id": "557058:dc3817de-7777-45cd-b81c-5c39d2560090",
"links": {
"self": {
"href": "https://api.bitbucket.org/2.0/users/lkysow"
Expand All @@ -138,7 +137,6 @@
"reason": "",
"updated_on": "2018-07-28T00:06:42.257659+00:00",
"author": {
"username": "lkysow",
"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"reason": "",
"updated_on": "2018-07-28T00:06:42.257659+00:00",
"author": {
"username": "lkysow",

"display_name": "Luke",
"account_id": "557058:dc3817de-68b5-45cd-b81c-5c39d2560090",
"links": {
Expand Down