2023-12-09 04:13:17 +00:00
|
|
|
package projects
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2023-12-10 04:19:19 +00:00
|
|
|
"path/filepath"
|
2023-12-09 04:13:17 +00:00
|
|
|
|
|
|
|
"gitlab.sweetwater.com/it/devops/tools/gitlab-project-manager/internal/gitlab"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (c *Cache) GoTo(project *gitlab.Project) {
|
2023-12-10 04:19:19 +00:00
|
|
|
pPath := c.GetProjectPath(project)
|
2023-12-09 04:13:17 +00:00
|
|
|
|
|
|
|
c.log.Debug("Going to project", c.log.Args(
|
|
|
|
"project", project.String(),
|
|
|
|
"path", pPath,
|
|
|
|
))
|
|
|
|
|
|
|
|
if _, err := os.Stat(pPath); err != nil {
|
|
|
|
c.log.Info("Preparing project path")
|
|
|
|
c.PrepProjectPath(pPath)
|
|
|
|
}
|
2023-12-10 04:19:19 +00:00
|
|
|
|
|
|
|
os.Chdir(filepath.Dir(pPath))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cache) IsProjectCloned(p *gitlab.Project) bool {
|
|
|
|
_, err := os.Stat(c.GetProjectPath(p) + "/.git")
|
|
|
|
if err == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2023-12-09 04:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cache) PrepProjectPath(path string) {
|
|
|
|
if err := os.MkdirAll(path, 0750); err != nil {
|
|
|
|
c.log.Fatal("Failed to prepare project path", c.log.Args(
|
|
|
|
"path", path,
|
|
|
|
"error", err,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|
2023-12-10 04:19:19 +00:00
|
|
|
|
|
|
|
func (c *Cache) GetProjectPath(p *gitlab.Project) string {
|
|
|
|
return c.path + "/" + p.SanitizedPath()
|
|
|
|
}
|