Merge pull request #273 from ygbillet/gitea-fix-list-repo

fix: gitea fetch remote repository with pagination
This commit is contained in:
Simone Gotti 2021-06-07 09:36:42 +02:00 committed by GitHub
commit 97ee680b72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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) {
remoteRepos, err := c.client.ListMyRepos(gitea.ListReposOptions{})
if err != nil {
return nil, err
}
page := 1
repos := []*gitsource.RepoInfo{}
for _, rr := range remoteRepos {
// keep only repos with admin permissions
if !rr.Permissions.Admin {
continue
}
repos = append(repos, fromGiteaRepo(rr))
}
for {
remoteRepos, err := c.client.ListMyRepos(
gitea.ListReposOptions{
ListOptions: gitea.ListOptions{
Page: page,
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
}