Skip to content
Snippets Groups Projects
Unverified Commit 61551d50 authored by Tomasz Maczukin's avatar Tomasz Maczukin
Browse files

Add PROJECT_NAMESPACE and PROJECT_NAME variables

Closes #185
parent 3b4893c7
No related tags found
No related merge requests found
...@@ -38,6 +38,9 @@ type Build struct { ...@@ -38,6 +38,9 @@ type Build struct {
// Unique ID for all running builds on this runner and this project // Unique ID for all running builds on this runner and this project
ProjectRunnerID int `json:"project_runner_id"` ProjectRunnerID int `json:"project_runner_id"`
ProjectName string
ProjectNamespace string
} }
func (b *Build) ProjectUniqueName() string { func (b *Build) ProjectUniqueName() string {
...@@ -63,9 +66,27 @@ func (b *Build) ProjectSlug() (string, error) { ...@@ -63,9 +66,27 @@ func (b *Build) ProjectSlug() (string, error) {
if strings.Contains(slug, "..") { if strings.Contains(slug, "..") {
return "", errors.New("it doesn't look like a valid path") return "", errors.New("it doesn't look like a valid path")
} }
return slug, nil return slug, nil
} }
func (b *Build) GetNamespaceAndName() (string, string) {
if b.ProjectNamespace != "" || b.ProjectName != "" {
return b.ProjectNamespace, b.ProjectName
}
slug, err := b.ProjectSlug()
if err != nil {
return "", ""
}
namespaceAndName := strings.Split(strings.TrimPrefix(slug, "/"), "/")
b.ProjectNamespace = namespaceAndName[0]
b.ProjectName = namespaceAndName[1]
return b.ProjectNamespace, b.ProjectName
}
func (b *Build) ProjectUniqueDir(sharedDir bool) string { func (b *Build) ProjectUniqueDir(sharedDir bool) string {
dir, err := b.ProjectSlug() dir, err := b.ProjectSlug()
if err != nil { if err != nil {
...@@ -128,6 +149,8 @@ func (b *Build) String() string { ...@@ -128,6 +149,8 @@ func (b *Build) String() string {
} }
func (b *Build) GetDefaultVariables() BuildVariables { func (b *Build) GetDefaultVariables() BuildVariables {
namespace, name := b.GetNamespaceAndName()
return BuildVariables{ return BuildVariables{
{"CI", "true", true, true, false}, {"CI", "true", true, true, false},
{"CI_BUILD_REF", b.Sha, true, true, false}, {"CI_BUILD_REF", b.Sha, true, true, false},
...@@ -142,6 +165,8 @@ func (b *Build) GetDefaultVariables() BuildVariables { ...@@ -142,6 +165,8 @@ func (b *Build) GetDefaultVariables() BuildVariables {
{"CI_SERVER_VERSION", "", true, true, false}, {"CI_SERVER_VERSION", "", true, true, false},
{"CI_SERVER_REVISION", "", true, true, false}, {"CI_SERVER_REVISION", "", true, true, false},
{"GITLAB_CI", "true", true, true, false}, {"GITLAB_CI", "true", true, true, false},
{"PROJECT_NAMESPACE", namespace, true, true, false},
{"PROJECT_NAME", name, true, true, false},
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment