Fetch all branches from gitea (#1231)

Both repo branch view and manual branch selector were limited to the
stock pageSize of gitea client.

this add a loop to fetch all branches from gitea
This commit is contained in:
[X] 2022-10-06 19:52:12 +02:00 committed by GitHub
parent 89466646d1
commit 3130a1c523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions

View file

@ -462,15 +462,29 @@ func (c *Gitea) Branches(ctx context.Context, u *model.User, r *model.Repo) ([]s
return nil, err
}
giteaBranches, _, err := client.ListRepoBranches(r.Owner, r.Name, gitea.ListRepoBranchesOptions{})
if err != nil {
return nil, err
branches := make([]string, 0)
page := 1
for {
giteaBranches, _, err := client.ListRepoBranches(r.Owner, r.Name, gitea.ListRepoBranchesOptions{
ListOptions: gitea.ListOptions{
Page: page,
},
})
if err != nil {
return nil, err
}
if len(giteaBranches) > 0 {
for _, branch := range giteaBranches {
branches = append(branches, branch.Name)
}
page++
} else {
break
}
}
branches := make([]string, 0)
for _, branch := range giteaBranches {
branches = append(branches, branch.Name)
}
return branches, nil
}

View file

@ -75,6 +75,7 @@ type Remote interface {
Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error
// Branches returns the names of all branches for the named repository.
// TODO: Add proper pagination handling and remove workaround in gitea remote
Branches(ctx context.Context, u *model.User, r *model.Repo) ([]string, error)
// BranchHead returns the sha of the head (lastest commit) of the specified branch