git-project-manager/internal/remotes/gitea/gitea_stream.go
2024-12-19 14:55:49 -05:00

49 lines
1.1 KiB
Go

package gitearemote
import (
"errors"
"code.gitea.io/sdk/gitea"
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/load"
"gitea.libretechconsulting.com/rmcguire/git-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)
r.setClient()
// 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.NextPage == 0 {
break
}
giteaListOpts.Page = resp.NextPage
}
pi.DoneChan <- nil
}