48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
|
package gitearemote
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"code.gitea.io/sdk/gitea"
|
||
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
|
||
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
||
|
)
|
||
|
|
||
|
const giteaReposPerPage = 20
|
||
|
|
||
|
func (r *GiteaRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) {
|
||
|
defer close(pi.ProgressChan)
|
||
|
defer close(pi.ProjectsChan)
|
||
|
|
||
|
// Get projects. TODO support concurrency
|
||
|
giteaListOpts := gitea.ListOptions{Page: 1, PageSize: giteaReposPerPage}
|
||
|
for {
|
||
|
repos, resp, err := r.api.ListMyRepos(gitea.ListReposOptions{ListOptions: giteaListOpts})
|
||
|
|
||
|
if err != nil {
|
||
|
pi.ErrorChan <- err
|
||
|
break
|
||
|
} else if len(repos) < 1 {
|
||
|
pi.ErrorChan <- errors.New("No gitea repos found")
|
||
|
break
|
||
|
}
|
||
|
|
||
|
// Write updates to channels
|
||
|
pi.ProjectsChan <- r.ReposToProjects(repos)
|
||
|
pi.ProgressChan <- load.Progress{
|
||
|
Page: giteaListOpts.Page,
|
||
|
Pages: resp.LastPage,
|
||
|
Projects: len(repos),
|
||
|
TotalProjects: pi.NumProjects,
|
||
|
}
|
||
|
|
||
|
if resp.LastPage == resp.NextPage {
|
||
|
break
|
||
|
}
|
||
|
|
||
|
giteaListOpts.Page = resp.NextPage
|
||
|
}
|
||
|
|
||
|
pi.DoneChan <- nil
|
||
|
}
|