Fix bitbucket branches pagination. (#2509)

This commit is contained in:
Michalis Zampetakis 2023-09-29 19:01:29 +03:00 committed by GitHub
parent 0eacbe8a33
commit 57b7b1788d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View file

@ -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

View file

@ -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
}