fix: gitea fetch remote repository with pagination

Actual implementation doesn't fetch all repository. Gitea API has
pagination.

This patch works wwith gitea pagination for repository listing

Signed-off-by: Yves-Gaël BILLET <yg.billet@gmail.com>
This commit is contained in:
Yves-Gaël Billet 2021-06-04 23:10:37 +02:00 committed by Yves-Gaël BILLET
parent 8b7596559b
commit 3dbf9a923f
1 changed files with 28 additions and 12 deletions

View File

@ -382,21 +382,37 @@ func (c *Client) CreateCommitStatus(repopath, commitSHA string, status gitsource
} }
func (c *Client) ListUserRepos() ([]*gitsource.RepoInfo, error) { func (c *Client) ListUserRepos() ([]*gitsource.RepoInfo, error) {
remoteRepos, err := c.client.ListMyRepos(gitea.ListReposOptions{}) page := 1
if err != nil {
return nil, err
}
repos := []*gitsource.RepoInfo{} repos := []*gitsource.RepoInfo{}
for _, rr := range remoteRepos { for {
// keep only repos with admin permissions remoteRepos, err := c.client.ListMyRepos(
if !rr.Permissions.Admin { gitea.ListReposOptions{
continue ListOptions: gitea.ListOptions{
} Page: page,
repos = append(repos, fromGiteaRepo(rr)) PageSize: 50, // Gitea SDK limit per page.
} },
},
)
if err != nil {
return []*gitsource.RepoInfo{}, err
}
for _, repo := range remoteRepos {
if !repo.Permissions.Admin {
continue
}
repos = append(repos, fromGiteaRepo(repo))
}
// Check if no more repos are available
if len(remoteRepos) == 0 {
break
} else {
page = page + 1
}
}
return repos, nil return repos, nil
} }