From ee4402b2e8fd2bc55e100cda72a19d5f40608d2e Mon Sep 17 00:00:00 2001 From: Philipp Heuer Date: Fri, 2 Aug 2024 20:12:21 +0200 Subject: [PATCH] fix: set Commit.RefRelease based on gitlab env value --- pkg/normalizer/gitlabci/normalize.go | 1 + pkg/vcsrepository/repository.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/normalizer/gitlabci/normalize.go b/pkg/normalizer/gitlabci/normalize.go index b436fa8..c812d19 100644 --- a/pkg/normalizer/gitlabci/normalize.go +++ b/pkg/normalizer/gitlabci/normalize.go @@ -74,6 +74,7 @@ func (n Normalizer) Normalize(env map[string]string) (v1.Spec, error) { nci.Commit.RefSlug = slug.Make(env["CI_COMMIT_REF_NAME"]) nci.Commit.RefVCS = "refs/heads/" + env["CI_COMMIT_REF_NAME"] } + nci.Commit.RefRelease = vcsrepository.ToReleaseName(nci.Commit.RefName) // project details projectData, err := projectdetails.GetProjectDetails(nci.Repository.Kind, nci.Repository.Remote, nci.Repository.HostType, nci.Repository.HostServer) diff --git a/pkg/vcsrepository/repository.go b/pkg/vcsrepository/repository.go index 4d8eca7..9dec824 100644 --- a/pkg/vcsrepository/repository.go +++ b/pkg/vcsrepository/repository.go @@ -58,7 +58,7 @@ func GetVCSRepositoryInformation(dir string) (RepositoryInformation, error) { result.Commit.RefVCS = client.VCSRefToInternalRef(head) // release name (=name, but without leading v, without slash) - result.Commit.RefRelease = getReleaseName(result.Commit.RefName) + result.Commit.RefRelease = ToReleaseName(result.Commit.RefName) // repository status (data[ncispec.NCI_REPOSITORY_STATUS]) // TODO: current isClean by go-git detects newlines as change, see https://github.com/go-git/go-git/issues/436 @@ -103,7 +103,7 @@ func GetVCSRepositoryInformation(dir string) (RepositoryInformation, error) { return result, nil } -func getReleaseName(input string) string { +func ToReleaseName(input string) string { input = slug.Substitute(input, map[string]string{ "/": "-", })