55 "fmt"
66 "io"
77 "strconv"
8- "strings"
98)
109
1110// GitSemVer holds git metadata used while computing a version.
@@ -58,7 +57,7 @@ func (vs *GitSemVer) IsReleaseBranch(branchName string) bool {
5857
5958 // GitLab gives us the default branch name directly.
6059 if defBranch , ok := vs .Env .LookupEnv ("CI_DEFAULT_BRANCH" ); ok {
61- return branchName == strings . TrimSpace ( defBranch )
60+ return branchName == defBranch
6261 }
6362
6463 // Fallback to common default branch names.
@@ -145,7 +144,7 @@ func (vs *GitSemVer) examineTags(repo string) (err error) {
145144// the closest semver tag if none match exactly. It also returns a bool
146145// that is true if the tree hashes match and there are no uncommitted changes.
147146func (vs * GitSemVer ) GetTag (repo string ) (tag string , match bool , err error ) {
148- if ciTag := strings . TrimSpace ( vs .Env .Getenv ("CI_COMMIT_TAG" ) ); ciTag != "" {
147+ if ciTag := vs .Env .Getenv ("CI_COMMIT_TAG" ); ciTag != "" {
149148 if isSemverTag (ciTag ) {
150149 return ciTag , true , nil
151150 }
@@ -179,9 +178,9 @@ type gitHubPullRequestEvent struct {
179178}
180179
181180func (vs * GitSemVer ) getBranchGitHub (repo string ) (branchName string , err error ) {
182- if branchName = strings . TrimSpace ( vs .Env .Getenv ("GITHUB_BASE_REF" ) ); branchName == "" {
183- if refName := strings . TrimSpace ( vs .Env .Getenv ("GITHUB_REF_NAME" ) ); refName != "" {
184- if strings . TrimSpace ( vs .Env .Getenv ("GITHUB_REF_TYPE" ) ) == "tag" {
181+ if branchName = vs .Env .Getenv ("GITHUB_BASE_REF" ); branchName == "" {
182+ if refName := vs .Env .Getenv ("GITHUB_REF_NAME" ); refName != "" {
183+ if vs .Env .Getenv ("GITHUB_REF_TYPE" ) == "tag" {
185184 var branches []string
186185 if branches , err = vs .Git .GetBranchesFromTag (repo , refName ); err == nil {
187186 for _ , branchName = range branches {
@@ -198,10 +197,10 @@ func (vs *GitSemVer) getBranchGitHub(repo string) (branchName string, err error)
198197}
199198
200199func (vs * GitSemVer ) getBranchGitLab (repo string ) (branchName string , err error ) {
201- if branchName = strings . TrimSpace ( vs .Env .Getenv ("CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ) ); branchName == "" {
202- if branchName = strings . TrimSpace ( vs .Env .Getenv ("CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME" ) ); branchName == "" {
203- if branchName = strings . TrimSpace ( vs .Env .Getenv ("CI_COMMIT_REF_NAME" ) ); branchName != "" {
204- if strings . TrimSpace ( vs .Env .Getenv ("CI_COMMIT_TAG" ) ) == branchName {
200+ if branchName = vs .Env .Getenv ("CI_MERGE_REQUEST_TARGET_BRANCH_NAME" ); branchName == "" {
201+ if branchName = vs .Env .Getenv ("CI_EXTERNAL_PULL_REQUEST_TARGET_BRANCH_NAME" ); branchName == "" {
202+ if branchName = vs .Env .Getenv ("CI_COMMIT_REF_NAME" ); branchName != "" {
203+ if vs .Env .Getenv ("CI_COMMIT_TAG" ) == branchName {
205204 var branches []string
206205 if branches , err = vs .Git .GetBranchesFromTag (repo , branchName ); err == nil {
207206 for _ , branchName = range branches {
@@ -236,8 +235,8 @@ func (vs *GitSemVer) GetBranch(repo string) (branchName string, err error) {
236235// otherwise the Git commit count is used. Returns an empty string if no reasonable build
237236// counter can be found.
238237func (vs * GitSemVer ) GetBuild (repo string ) (build string , err error ) {
239- if build = strings . TrimSpace ( vs .Env .Getenv ("CI_PIPELINE_IID" ) ); build == "" {
240- if build = strings . TrimSpace ( vs .Env .Getenv ("GITHUB_RUN_NUMBER" ) ); build == "" {
238+ if build = vs .Env .Getenv ("CI_PIPELINE_IID" ); build == "" {
239+ if build = vs .Env .Getenv ("GITHUB_RUN_NUMBER" ); build == "" {
241240 build , err = vs .Git .GetBuild (repo )
242241 }
243242 }
0 commit comments