From f71f8d1ee07f159b823706824b829e881e5d448c Mon Sep 17 00:00:00 2001 From: Ryan D McGuire Date: Wed, 6 Mar 2024 16:21:52 -0500 Subject: [PATCH] Only initiate Gitea client on use --- internal/remotes/gitea/gitea.go | 10 ++++++---- internal/remotes/gitea/gitea_api.go | 1 + internal/remotes/gitea/gitea_stream.go | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/remotes/gitea/gitea.go b/internal/remotes/gitea/gitea.go index 26563fd..ef68d41 100644 --- a/internal/remotes/gitea/gitea.go +++ b/internal/remotes/gitea/gitea.go @@ -29,10 +29,12 @@ func (r *GiteaRemote) String() string { // Prepares the Gitea api client func (r *GiteaRemote) setClient() error { var err error - r.api, err = gitea.NewClient(r.info.Host, - gitea.SetContext(r.info.Context()), - gitea.SetToken(r.info.Token), - ) + if r.api == nil { + r.api, err = gitea.NewClient(r.info.Host, + gitea.SetContext(r.info.Context()), + gitea.SetToken(r.info.Token), + ) + } return err } diff --git a/internal/remotes/gitea/gitea_api.go b/internal/remotes/gitea/gitea_api.go index b892fc1..c6d18e5 100644 --- a/internal/remotes/gitea/gitea_api.go +++ b/internal/remotes/gitea/gitea_api.go @@ -75,6 +75,7 @@ func GetOwnerRepo(fullName string) (string, string) { func (r *GiteaRemote) GetNumProjects(opts *remote.RemoteQueryOpts) int { var projects int + r.setClient() _, resp, err := r.api.SearchRepos(gitea.SearchRepoOptions{ListOptions: gitea.ListOptions{PageSize: 1}}) if err != nil { diff --git a/internal/remotes/gitea/gitea_stream.go b/internal/remotes/gitea/gitea_stream.go index f148ad2..263982d 100644 --- a/internal/remotes/gitea/gitea_stream.go +++ b/internal/remotes/gitea/gitea_stream.go @@ -13,6 +13,7 @@ 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}