Move from --gitlab flags to global --remote flags
This commit is contained in:
16
internal/cache/cache.go
vendored
16
internal/cache/cache.go
vendored
@ -17,7 +17,7 @@ type Cache struct {
|
||||
Projects []*projects.Project
|
||||
Aliases []*ProjectAlias
|
||||
Updated time.Time
|
||||
Remotes *remotes.Remotes
|
||||
remotes *remotes.Remotes
|
||||
config *config.Config
|
||||
readFromFile bool
|
||||
lock *sync.Mutex // Lock the entire cache
|
||||
@ -138,22 +138,22 @@ func (c *Cache) Clear(clearAliases bool) {
|
||||
c.clear(clearAliases)
|
||||
}
|
||||
|
||||
func (c *Cache) refresh() {
|
||||
func (c *Cache) refresh(remotes ...string) {
|
||||
c.log.Info("Loading project cache, this may take a while\n")
|
||||
defer c.setUpdated()
|
||||
// Fix any dangling aliases
|
||||
// For backwards-compatibility only
|
||||
c.setAliasRemotes()
|
||||
// Retrieve and add/update projects
|
||||
c.LoadRemotes()
|
||||
c.LoadRemotes(remotes...)
|
||||
}
|
||||
|
||||
// Iterates through all GitLab projects the user has access to, updating
|
||||
// the project cache where necessary
|
||||
func (c *Cache) Refresh() {
|
||||
func (c *Cache) Refresh(remotes ...string) {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
c.refresh()
|
||||
c.refresh(remotes...)
|
||||
}
|
||||
|
||||
func (c *Cache) String() string {
|
||||
@ -161,9 +161,9 @@ func (c *Cache) String() string {
|
||||
c.Updated.String(),
|
||||
len(c.Projects),
|
||||
len(c.Aliases),
|
||||
len(*c.Remotes),
|
||||
len(*c.remotes),
|
||||
)
|
||||
for _, r := range *c.Remotes {
|
||||
for _, r := range *c.remotes {
|
||||
cacheString += " " + r.GetInfo().Host
|
||||
}
|
||||
return cacheString
|
||||
@ -202,7 +202,7 @@ func NewProjectCache(opts *CacheOpts) (*Cache, error) {
|
||||
lock: &sync.Mutex{},
|
||||
contentLock: &sync.Mutex{},
|
||||
log: opts.Logger,
|
||||
Remotes: opts.Remotes,
|
||||
remotes: opts.Remotes,
|
||||
path: opts.ProjectsPath,
|
||||
}
|
||||
|
||||
|
13
internal/cache/cache_load.go
vendored
13
internal/cache/cache_load.go
vendored
@ -8,17 +8,24 @@ import (
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/load"
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/remote"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
func (c *Cache) LoadRemotes() {
|
||||
func (c *Cache) LoadRemotes(gitRemotes ...string) {
|
||||
wg := &sync.WaitGroup{}
|
||||
writer := pterm.DefaultMultiPrinter
|
||||
|
||||
for _, r := range *c.Remotes {
|
||||
for _, r := range *c.remotes {
|
||||
// Don't bother if it's dead or the user has provided
|
||||
// one or more remotes via --remote flag(s)
|
||||
if !remote.IsAlive(r) {
|
||||
c.log.Error("Skipping load of remote, not alive", c.log.Args(
|
||||
"remote", r.String()))
|
||||
continue
|
||||
} else if !slices.Contains(gitRemotes, r.GetInfo().Host) {
|
||||
c.log.Debug("Skipping remote not in --remote list", c.log.Args(
|
||||
"remote", r.String(),
|
||||
))
|
||||
"remotes", gitRemotes))
|
||||
continue
|
||||
}
|
||||
|
||||
|
4
internal/cache/cache_projects.go
vendored
4
internal/cache/cache_projects.go
vendored
@ -43,7 +43,7 @@ func (c *Cache) AddProjects(gitProjects ...*projects.Project) {
|
||||
|
||||
// This command will only dump projects that have
|
||||
// been cloned locally. Setting all to true will list all projects
|
||||
func (c *Cache) DumpString(all bool, search string, gitlabs ...string) string {
|
||||
func (c *Cache) DumpString(all bool, search string, remotes ...string) string {
|
||||
str := strings.Builder{}
|
||||
var term string
|
||||
if all {
|
||||
@ -56,7 +56,7 @@ func (c *Cache) DumpString(all bool, search string, gitlabs ...string) string {
|
||||
for _, project := range projects {
|
||||
if !all && !c.IsProjectCloned(project) {
|
||||
continue
|
||||
} else if len(gitlabs) > 0 && !slices.Contains(gitlabs, project.Remote) {
|
||||
} else if len(remotes) > 0 && !slices.Contains(remotes, project.Remote) {
|
||||
continue
|
||||
}
|
||||
str.WriteString(" - " + pterm.FgLightBlue.Sprint(project.Name) + " (")
|
||||
|
4
internal/cache/projects_alias.go
vendored
4
internal/cache/projects_alias.go
vendored
@ -71,9 +71,9 @@ func (c *Cache) AliasStrings(prefix string) []string {
|
||||
return aliases
|
||||
}
|
||||
|
||||
func (c *Cache) GetAliasByName(name string, gitlabs ...string) *ProjectAlias {
|
||||
func (c *Cache) GetAliasByName(name string, remotes ...string) *ProjectAlias {
|
||||
for _, a := range c.Aliases {
|
||||
if len(gitlabs) > 0 && !slices.Contains(gitlabs, a.Remote) {
|
||||
if len(remotes) > 0 && !slices.Contains(remotes, a.Remote) {
|
||||
continue
|
||||
}
|
||||
if name == a.Alias {
|
||||
|
Reference in New Issue
Block a user