fix: remove directory from project name when context is self

This commit is contained in:
Beau 2024-03-22 20:01:39 +00:00
parent 6c13d2d7f9
commit 4a8ad0cc09
No known key found for this signature in database

View File

@ -9,8 +9,15 @@ import (
func ptr[T any](v T) *T { return &v } func ptr[T any](v T) *T { return &v }
// friendlyName creates a contextual name used for Atlantis projects // friendlyName creates a contextual name used for Atlantis projects
func friendlyName(path, environment string) string { func friendlyName(path, varFile string) string {
name := []string{strings.ReplaceAll(path, "/", "-"), pathWithoutExtension(filepath.Base(environment))} environment := pathWithoutExtension(filepath.Base(varFile))
// avoid constructing a joined path if the context is the current directory
if filepath.Base(path) == "." {
return environment
}
name := []string{strings.ReplaceAll(path, "/", "-"), environment}
return strings.TrimSuffix(strings.Join(name, "-"), "-") return strings.TrimSuffix(strings.Join(name, "-"), "-")
} }