package githubremote import ( "errors" "github.com/google/go-github/v58/github" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/load" "gitea.libretechconsulting.com/rmcguire/git-project-manager/internal/remotes/remote" ) const githubReposPerPage = 20 func (r *GithubRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) { defer close(pi.ProgressChan) defer close(pi.ProjectsChan) // Get projects. TODO support concurrency githubListOpts := github.ListOptions{ Page: 1, PerPage: githubReposPerPage, } var githubRepoType string if opts.OwnerOnly { githubRepoType = "owner" } else { githubRepoType = "all" } for { repos, resp, err := r.api.Repositories.ListByAuthenticatedUser( r.info.Context(), &github.RepositoryListByAuthenticatedUserOptions{ Type: githubRepoType, ListOptions: githubListOpts, }, ) if err != nil { pi.ErrorChan <- err break } else if len(repos) < 1 { pi.ErrorChan <- errors.New("No github repos found") break } // Write updates to channels pi.ProjectsChan <- r.ReposToProjects(repos) pi.ProgressChan <- load.Progress{ Page: githubListOpts.Page, Pages: resp.LastPage, Projects: len(repos), TotalProjects: pi.NumProjects, } if resp.NextPage == 0 { break } githubListOpts.Page = resp.NextPage } pi.DoneChan <- nil }