Only initiate Gitea client on use

This commit is contained in:
Ryan McGuire 2024-03-06 16:21:52 -05:00
parent 8764edad99
commit f71f8d1ee0
3 changed files with 8 additions and 4 deletions

View File

@ -29,10 +29,12 @@ func (r *GiteaRemote) String() string {
// Prepares the Gitea api client // Prepares the Gitea api client
func (r *GiteaRemote) setClient() error { func (r *GiteaRemote) setClient() error {
var err error var err error
if r.api == nil {
r.api, err = gitea.NewClient(r.info.Host, r.api, err = gitea.NewClient(r.info.Host,
gitea.SetContext(r.info.Context()), gitea.SetContext(r.info.Context()),
gitea.SetToken(r.info.Token), gitea.SetToken(r.info.Token),
) )
}
return err return err
} }

View File

@ -75,6 +75,7 @@ func GetOwnerRepo(fullName string) (string, string) {
func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int { func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int {
var projects int var projects int
r.setClient()
_, resp, err := r.api.SearchRepos(gitea.SearchRepoOptions{ListOptions: gitea.ListOptions{PageSize: 1}}) _, resp, err := r.api.SearchRepos(gitea.SearchRepoOptions{ListOptions: gitea.ListOptions{PageSize: 1}})
if err != nil { if err != nil {

View File

@ -13,6 +13,7 @@ const giteaReposPerPage = 20
func (r *GiteaRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) { func (r *GiteaRemote) StreamProjects(pi *load.ProgressInfo, opts *remote.RemoteQueryOpts) {
defer close(pi.ProgressChan) defer close(pi.ProgressChan)
defer close(pi.ProjectsChan) defer close(pi.ProjectsChan)
r.setClient()
// Get projects. TODO support concurrency // Get projects. TODO support concurrency
giteaListOpts := gitea.ListOptions{Page: 1, PageSize: giteaReposPerPage} giteaListOpts := gitea.ListOptions{Page: 1, PageSize: giteaReposPerPage}