mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-11 01:55:27 +00:00
Incomplete Gitea repository list fixed
Woodpecker may display incomplete list of Gitea repositores user has access to because Gitea forces paginated repo list reading. This mod fixes it. Related: https://gitea.com/gitea/go-sdk/issues/507 Author-Change-Id: IB#1107754
This commit is contained in:
parent
b52e404f93
commit
e96a17dc9e
1 changed files with 36 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
// Copyright 2018 Drone.IO Inc.
|
||||
// Copyright 2021 Informatyka Boguslawski sp. z o.o. sp.k., http://www.ib.pl/
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
@ -11,6 +12,8 @@
|
|||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
// This file has been modified by Informatyka Boguslawski sp. z o.o.
|
||||
|
||||
package gitea
|
||||
|
||||
|
@ -229,15 +232,41 @@ func (c *client) Repos(u *model.User) ([]*model.Repo, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
all, _, err := client.ListMyRepos(gitea.ListReposOptions{})
|
||||
if err != nil {
|
||||
return repos, err
|
||||
// Gitea SDK forces us to read repo list paginated.
|
||||
var page int = 1
|
||||
for {
|
||||
all, _, err := client.ListMyRepos(
|
||||
gitea.ListReposOptions{
|
||||
ListOptions: gitea.ListOptions{
|
||||
Page: page,
|
||||
PageSize: 50, // Gitea SDK limit per page.
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
// Gitea SDK does not return error when asking for
|
||||
// non existing repos page (empty list is returned)
|
||||
// so this should be safe.
|
||||
if err != nil {
|
||||
return repos, err
|
||||
}
|
||||
|
||||
for _, repo := range all {
|
||||
repos = append(repos, toRepo(repo, c.PrivateMode))
|
||||
}
|
||||
|
||||
// Check if no more repos are available; we don't test len(all) < 50
|
||||
// because of Gitea SDK bug https://gitea.com/gitea/go-sdk/issues/507.
|
||||
if len(all) == 0 {
|
||||
// Empty page returned - finish loop.
|
||||
break
|
||||
} else {
|
||||
// Last page was not empty so more repos may be available - continue loop.
|
||||
page = page + 1
|
||||
}
|
||||
}
|
||||
|
||||
for _, repo := range all {
|
||||
repos = append(repos, toRepo(repo, c.PrivateMode))
|
||||
}
|
||||
return repos, err
|
||||
return repos, nil
|
||||
}
|
||||
|
||||
// Perm returns the user permissions for the named Gitea repository.
|
||||
|
|
Loading…
Reference in a new issue