From e7a2a04e74f3f85b87b1f0627bb0322ca854234b Mon Sep 17 00:00:00 2001 From: Michalis Zampetakis Date: Thu, 28 Sep 2023 21:25:54 +0300 Subject: [PATCH] Fix bitbucket branches pagination. Closes: #2506 --- server/forge/bitbucket/bitbucket.go | 8 ++++---- server/forge/bitbucket/internal/client.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/forge/bitbucket/bitbucket.go b/server/forge/bitbucket/bitbucket.go index a8e6ca3a87..a490ea1d4c 100644 --- a/server/forge/bitbucket/bitbucket.go +++ b/server/forge/bitbucket/bitbucket.go @@ -327,12 +327,12 @@ func (c *config) Netrc(u *model.User, _ *model.Repo) (*model.Netrc, error) { } // Branches returns the names of all branches for the named repository. -func (c *config) Branches(ctx context.Context, u *model.User, r *model.Repo, _ *model.ListOptions) ([]string, error) { - bitbucketBranches, err := c.newClient(ctx, u).ListBranches(r.Owner, r.Name) +func (c *config) Branches(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]string, error) { + opts := internal.ListOpts{Page: p.Page, PageLen: p.PerPage} + bitbucketBranches, err := c.newClient(ctx, u).ListBranches(r.Owner, r.Name, &opts) if err != nil { return nil, err } - branches := make([]string, 0) for _, branch := range bitbucketBranches { branches = append(branches, branch.Name) @@ -347,7 +347,7 @@ func (c *config) BranchHead(ctx context.Context, u *model.User, r *model.Repo, b // PullRequests returns the pull requests of the named repository. func (c *config) PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error) { - opts := internal.ListOpts{Page: p.Page, PageLen: p.Page} + opts := internal.ListOpts{Page: p.Page, PageLen: p.PerPage} pullRequests, err := c.newClient(ctx, u).ListPullRequests(r.Owner, r.Name, &opts) if err != nil { return nil, err diff --git a/server/forge/bitbucket/internal/client.go b/server/forge/bitbucket/internal/client.go index 35e309f6b2..04eca60919 100644 --- a/server/forge/bitbucket/internal/client.go +++ b/server/forge/bitbucket/internal/client.go @@ -44,7 +44,7 @@ const ( pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s" pathSource = "%s/2.0/repositories/%s/%s/src/%s/%s" pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build" - pathBranches = "%s/2.0/repositories/%s/%s/refs/branches" + pathBranches = "%s/2.0/repositories/%s/%s/refs/branches?%s" pathOrgPerms = "%s/2.0/workspaces/%s/permissions?%s" pathPullRequests = "%s/2.0/repositories/%s/%s/pullrequests" pathBranchCommits = "%s/2.0/repositories/%s/%s/commits/%s" @@ -178,9 +178,9 @@ func (c *Client) GetPermission(fullName string) (*RepoPerm, error) { return out.Values[0], nil } -func (c *Client) ListBranches(owner, name string) ([]*Branch, error) { +func (c *Client) ListBranches(owner, name string, opts *ListOpts) ([]*Branch, error) { out := new(BranchResp) - uri := fmt.Sprintf(pathBranches, c.base, owner, name) + uri := fmt.Sprintf(pathBranches, c.base, owner, name, opts.Encode()) _, err := c.do(uri, get, nil, out) return out.Values, err }