Delay creation of Gitea client TBC

This commit is contained in:
Ryan McGuire 2024-03-05 16:55:01 -05:00
parent ea7367ec08
commit 8764edad99

View File

@ -2,6 +2,7 @@ package gitearemote
import ( import (
"fmt" "fmt"
"net/url"
"code.gitea.io/sdk/gitea" "code.gitea.io/sdk/gitea"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info" "gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/info"
@ -25,19 +26,25 @@ func (r *GiteaRemote) String() string {
r.GetInfo().Name, r.GetInfo().Host, r.GetInfo().CloneProto) r.GetInfo().Name, r.GetInfo().Host, r.GetInfo().CloneProto)
} }
func NewGiteaRemote(remoteInfo *info.RemoteInfo) (*GiteaRemote, error) { // Prepares the Gitea api client
client, err := gitea.NewClient(remoteInfo.Host, func (r *GiteaRemote) setClient() error {
gitea.SetContext(remoteInfo.Context()), var err error
gitea.SetToken(remoteInfo.Token), r.api, err = gitea.NewClient(r.info.Host,
gitea.SetContext(r.info.Context()),
gitea.SetToken(r.info.Token),
) )
return err
}
if err != nil { // Does not prepare the client due to the Gitea client making an initial
// http connection. API client to be set on-demand
func NewGiteaRemote(remoteInfo *info.RemoteInfo) (*GiteaRemote, error) {
if _, err := url.Parse(remoteInfo.Host); err != nil {
return nil, err return nil, err
} }
giteaRemote := &GiteaRemote{ giteaRemote := &GiteaRemote{
info: remoteInfo, info: remoteInfo,
api: client,
} }
return giteaRemote, nil return giteaRemote, nil