From 89ef3563dba240f3af7b37227a732eeff1b41285 Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:02:24 +0530 Subject: [PATCH] fix: Bitbucket Cloud PR Author is processed correctly (#20769) (#20990) (#21039) Fixes #20769 Author there is a struct, not a string. Use nickname from that struct as an author name. Let's cherry pick to 2.11-2.13 Signed-off-by: Andrii Korotkov Co-authored-by: Andrii Korotkov <137232734+andrii-korotkov-verkada@users.noreply.github.com> --- .../services/pull_request/bitbucket_cloud.go | 9 ++++-- .../pull_request/bitbucket_cloud_test.go | 28 ++++++++++++++----- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/applicationset/services/pull_request/bitbucket_cloud.go b/applicationset/services/pull_request/bitbucket_cloud.go index 48083dcb407e3..2ee79d2cfabee 100644 --- a/applicationset/services/pull_request/bitbucket_cloud.go +++ b/applicationset/services/pull_request/bitbucket_cloud.go @@ -19,7 +19,7 @@ type BitbucketCloudPullRequest struct { ID int `json:"id"` Title string `json:"title"` Source BitbucketCloudPullRequestSource `json:"source"` - Author string `json:"author"` + Author BitbucketCloudPullRequestAuthor `json:"author"` } type BitbucketCloudPullRequestSource struct { @@ -35,6 +35,11 @@ type BitbucketCloudPullRequestSourceCommit struct { Hash string `json:"hash"` } +// Also have display_name and uuid, but don't plan to use them. +type BitbucketCloudPullRequestAuthor struct { + Nickname string `json:"nickname"` +} + type PullRequestResponse struct { Page int32 `json:"page"` Size int32 `json:"size"` @@ -134,7 +139,7 @@ func (b *BitbucketCloudService) List(_ context.Context) ([]*PullRequest, error) Title: pull.Title, Branch: pull.Source.Branch.Name, HeadSHA: pull.Source.Commit.Hash, - Author: pull.Author, + Author: pull.Author.Nickname, }) } diff --git a/applicationset/services/pull_request/bitbucket_cloud_test.go b/applicationset/services/pull_request/bitbucket_cloud_test.go index 8d5f7d80ca144..77cca79a8019f 100644 --- a/applicationset/services/pull_request/bitbucket_cloud_test.go +++ b/applicationset/services/pull_request/bitbucket_cloud_test.go @@ -37,7 +37,9 @@ func defaultHandlerCloud(t *testing.T) func(http.ResponseWriter, *http.Request) "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`) @@ -154,7 +156,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } }, { "id": 102, @@ -168,7 +172,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "4cf807e67a6d" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -191,7 +197,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "6344d9623e3b" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -339,7 +347,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } }, { "id": 200, @@ -353,7 +363,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "4cf807e67a6d" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -376,7 +388,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "6344d9623e3b" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host))