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) { 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
} }