Skip to content

Commit

Permalink
Fix bitbucket branches pagination.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michalis Zampetakis authored and mzampetakis committed Sep 28, 2023
1 parent 0eacbe8 commit e7a2a04
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions server/forge/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions server/forge/bitbucket/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e7a2a04

Please sign in to comment.