Migrate to remotes interface

This commit is contained in:
2024-01-16 12:48:42 -05:00
parent 5337ea544b
commit e7f8b86f72
13 changed files with 160 additions and 283 deletions

View File

@@ -10,7 +10,6 @@ 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,8 +25,7 @@ type Cache struct {
file string
log *pterm.Logger
path string
gitlabs *remotes.Clients
remotes *remote.Remotes
remotes *remotes.Remotes
}
type CacheOpts struct {
@@ -35,8 +33,7 @@ type CacheOpts struct {
ProjectsPath string
TTL time.Duration
Logger *pterm.Logger
Gitlabs *remotes.Clients
Remotes *remote.Remotes
Remotes *remotes.Remotes
Config *config.Config
}
@@ -148,7 +145,7 @@ func (c *Cache) refresh() {
// For backwards-compatibility only
c.setAliasRemotes()
// Retrieve and add/update projects
c.LoadGitlabs()
c.LoadRemotes()
}
// Iterates through all GitLab projects the user has access to, updating
@@ -164,10 +161,10 @@ func (c *Cache) String() string {
c.Updated.String(),
len(c.Projects),
len(c.Aliases),
len(*c.gitlabs),
len(*c.remotes),
)
for _, r := range *c.gitlabs {
cacheString += " " + r.Config.Host
for _, r := range *c.remotes {
cacheString += " " + r.GetInfo().Host
}
return cacheString
}
@@ -196,14 +193,6 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) {
err = createProjectCache(opts.Path)
}
// Combine old-and-new gitlabs
var gitlabs *remotes.Clients
if opts.Gitlabs != nil {
gitlabs = opts.Gitlabs
} else {
gitlabs = remotes.NewCLients()
}
cache := &Cache{
Projects: make([]*projects.Project, 0),
Aliases: make([]*ProjectAlias, 0),
@@ -213,8 +202,7 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) {
lock: &sync.Mutex{},
contentLock: &sync.Mutex{},
log: opts.Logger,
gitlabs: gitlabs,
remotes: remote.NewRemotes(),
remotes: opts.Remotes,
path: opts.ProjectsPath,
}