Fix bugs, set constants

This commit is contained in:
2024-10-01 14:29:14 -04:00
parent a54f0629be
commit 03fcbe41ae
20 changed files with 165 additions and 89 deletions

View File

@ -4,6 +4,8 @@ import (
"strings"
"github.com/lithammer/fuzzysearch/fuzzy"
"golang.org/x/exp/slices"
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/remotes/projects"
)
@ -27,14 +29,16 @@ func (c *Cache) FuzzyFindAlias(name string) []*ProjectAlias {
c.log.Debug("Fuzzy found multiple aliases, try being more specific",
c.log.Args("foundAliases", strings.Join(found, ", ")))
}
var aliases []*ProjectAlias
aliases := make([]*ProjectAlias, 0, ranks.Len())
if ranks.Len() > 0 {
aliases = make([]*ProjectAlias, ranks.Len())
for i, r := range ranks {
aliases[i] = c.GetAliasByName(r.Target)
for _, r := range ranks {
alias := c.GetAliasByName(r.Target)
if alias != nil {
aliases = append(aliases, alias)
}
}
}
return aliases
return slices.Clip(aliases)
}
// Returns all matching projects by fuzzy find term

View File

@ -48,14 +48,11 @@ func (c *Cache) GetProjectFromCwd() (*projects.Project, error) {
func (c *Cache) IsProjectCloned(p *projects.Project) bool {
_, err := os.Stat(c.GetProjectPath(p) + "/.git")
if err == nil {
return true
}
return false
return err == nil
}
func (c *Cache) PrepProjectPath(path string) {
if err := os.MkdirAll(path, 0750); err != nil {
if err := os.MkdirAll(path, 0o750); err != nil {
c.log.Fatal("Failed to prepare project path", c.log.Args(
"path", path,
"error", err,