Skip to content

Commit a6d5e57

Browse files
committed
clean up getBranchGitHub
1 parent 83ca65c commit a6d5e57

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

internal/gitsemver/gitsemver.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,24 +158,22 @@ func (vs *GitSemVer) GetTag(repo string) (tag string, match bool, err error) {
158158
func (vs *GitSemVer) getBranchGitHub(repo string) (branchName string, err error) {
159159
// Pull request events expose the source branch as GITHUB_HEAD_REF.
160160
// Prefer this so PR builds are not mistaken for base-branch releases.
161-
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_HEAD_REF")); branchName != "" {
162-
return
163-
}
164-
refName := strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_NAME"))
165-
if refName == "" {
166-
// Fallback for contexts that only expose a base branch.
167-
branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_BASE_REF"))
168-
return
169-
}
170-
if strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_TYPE")) != "tag" {
171-
return refName, nil
172-
}
173-
var branches []string
174-
if branches, err = vs.Git.GetBranchesFromTag(repo, refName); err == nil {
175-
for _, candidate := range branches {
176-
if vs.IsReleaseBranch(candidate) {
177-
return candidate, nil
161+
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_HEAD_REF")); branchName == "" {
162+
if branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_NAME")); branchName != "" {
163+
if strings.TrimSpace(vs.Env.Getenv("GITHUB_REF_TYPE")) == "tag" {
164+
var branches []string
165+
if branches, err = vs.Git.GetBranchesFromTag(repo, branchName); err == nil {
166+
for _, branchName = range branches {
167+
if vs.IsReleaseBranch(branchName) {
168+
return
169+
}
170+
}
171+
}
172+
branchName = ""
178173
}
174+
} else {
175+
// Fallback for contexts that only expose a base branch.
176+
branchName = strings.TrimSpace(vs.Env.Getenv("GITHUB_BASE_REF"))
179177
}
180178
}
181179
return

0 commit comments

Comments
 (0)