From b8e118ff7d08176538e48b09405d162e5ad31eec Mon Sep 17 00:00:00 2001 From: Andrii Korotkov <137232734+andrii-korotkov-verkada@users.noreply.github.com> Date: Tue, 3 Dec 2024 00:52:22 -0800 Subject: [PATCH] fix: Bitbucket Cloud PR Author is processed correctly (#20769) (#20990) 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 --- .../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 2e41c110bcd92..411f6148c85d6 100644 --- a/applicationset/services/pull_request/bitbucket_cloud_test.go +++ b/applicationset/services/pull_request/bitbucket_cloud_test.go @@ -38,7 +38,9 @@ func defaultHandlerCloud(t *testing.T) func(http.ResponseWriter, *http.Request) "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`) @@ -155,7 +157,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } }, { "id": 102, @@ -169,7 +173,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "4cf807e67a6d" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -192,7 +198,9 @@ func TestListPullRequestPaginationCloud(t *testing.T) { "hash": "6344d9623e3b" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -340,7 +348,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "1a8dd249c04a" } }, - "author": "testName" + "author": { + "nickname": "testName" + } }, { "id": 200, @@ -354,7 +364,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "4cf807e67a6d" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host)) @@ -377,7 +389,9 @@ func TestListPullRequestBranchMatchCloud(t *testing.T) { "hash": "6344d9623e3b" } }, - "author": "testName" + "author": { + "nickname": "testName" + } } ] }`, r.Host))