Improve project show and add pshow func with cwd support
This commit is contained in:
@ -90,6 +90,15 @@ func (c *Cache) GetAliasByName(name string) *ProjectAlias {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByPath(path string) *gitlab.Project {
|
||||
for _, p := range c.Projects {
|
||||
if p.PathWithNamespace == path {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectByID(id int) *gitlab.Project {
|
||||
for _, p := range c.Projects {
|
||||
if p.ID == id {
|
||||
|
@ -1,8 +1,10 @@
|
||||
package projects
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
||||
)
|
||||
@ -23,6 +25,27 @@ func (c *Cache) GoTo(project *gitlab.Project) {
|
||||
os.Chdir(filepath.Dir(pPath))
|
||||
}
|
||||
|
||||
func (c *Cache) GetProjectFromCwd() (*gitlab.Project, error) {
|
||||
var project *gitlab.Project
|
||||
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return project, err
|
||||
} else if !strings.HasPrefix(cwd, c.path) {
|
||||
return project, errors.New("Not in any project path")
|
||||
}
|
||||
|
||||
// Strip projects dir from path
|
||||
pathWithNs := cwd[len(c.path)+1:]
|
||||
c.log.Debug("Fetching project from current path", c.log.Args(
|
||||
"cwd", cwd, "pathWithNamespace", pathWithNs,
|
||||
))
|
||||
|
||||
project = c.GetProjectByPath(pathWithNs)
|
||||
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func (c *Cache) IsProjectCloned(p *gitlab.Project) bool {
|
||||
_, err := os.Stat(c.GetProjectPath(p) + "/.git")
|
||||
if err == nil {
|
||||
|
Reference in New Issue
Block a user