git-project-manager/internal/remotes/gitea/gitea_stream.go

49 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-01-16 20:46:32 +00:00
package gitearemote
import (
"errors"
"code.gitea.io/sdk/gitea"
2024-12-19 19:55:49 +00:00
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/load"
"gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/remote"
2024-01-16 20:46:32 +00:00
)
const giteaReposPerPage = 20
func (r *GiteaRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) {
defer close(pi.ProgressChan)
defer close(pi.ProjectsChan)
2024-03-06 21:21:52 +00:00
r.setClient()
2024-01-16 20:46:32 +00:00
// 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,
}
2024-01-18 16:10:18 +00:00
if resp.NextPage == 0 {
2024-01-16 20:46:32 +00:00
break
}
giteaListOpts.Page = resp.NextPage
}
pi.DoneChan <- nil
}