Start moving gitlab code to remote interface

This commit is contained in:
2024-01-16 11:15:52 -05:00
parent e846821c44
commit d7181b1cf6
11 changed files with 339 additions and 186 deletions

View File

@ -10,6 +10,7 @@ import (
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/config"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
"gopkg.in/yaml.v3"
)
@ -26,6 +27,7 @@ type Cache struct {
log *pterm.Logger
path string
gitlabs *remotes.Clients
remotes *remote.Remotes
}
type CacheOpts struct {
@ -34,6 +36,7 @@ type CacheOpts struct {
TTL time.Duration
Logger *pterm.Logger
Gitlabs *remotes.Clients
Remotes *remote.Remotes
Config *config.Config
}
@ -211,6 +214,7 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) {
contentLock: &sync.Mutex{},
log: opts.Logger,
gitlabs: gitlabs,
remotes: remote.NewRemotes(),
path: opts.ProjectsPath,
}

View File

@ -43,6 +43,27 @@ func (c *Cache) LoadGitlabs() {
fmt.Println("")
}
func (c *Cache) LoadRemote(client *remotes.Client, wg *sync.WaitGroup, pBar *pterm.ProgressbarPrinter, projects int) {
defer wg.Done()
progressInfo := client.StreamProjects(c.config.Cache.Load.OwnerOnly, projects)
for {
select {
case p := <-progressInfo.ProgressChan:
pBar.Add(p.Projects)
case p := <-progressInfo.ProjectsChan:
c.AddProjects(p...)
case e := <-progressInfo.ErrorChan:
c.log.Error("Fetch projects error", c.log.Args("error", e, "remote", client.Config.Name))
case <-client.Ctx.Done():
c.log.Warn("LoadProjects cancelled", c.log.Args("reason", client.Ctx.Err()))
return
case <-progressInfo.DoneChan:
return
}
}
}
func (c *Cache) LoadGitlab(client *remotes.Client, wg *sync.WaitGroup, pBar *pterm.ProgressbarPrinter, projects int) {
defer wg.Done()
progressInfo := client.StreamProjects(c.config.Cache.Load.OwnerOnly, projects)
@ -54,7 +75,7 @@ func (c *Cache) LoadGitlab(client *remotes.Client, wg *sync.WaitGroup, pBar *pte
case p := <-progressInfo.ProjectsChan:
c.AddProjects(p...)
case e := <-progressInfo.ErrorChan:
c.log.Error("Fetch GitLab projects error", c.log.Args("error", e, "gitlab", client.Config.Name))
c.log.Error("Fetch projects error", c.log.Args("error", e, "remote", client.Config.Name))
case <-client.Ctx.Done():
c.log.Warn("LoadProjects cancelled", c.log.Args("reason", client.Ctx.Err()))
return