Skip to content

Commit 0833270

Browse files
committed
fix: refactor to pass linter
1 parent 97baea3 commit 0833270

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

cmd/gorepomod/internal/git/runner.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ func (gr *Runner) LoadRemoteTags(
174174
_, err = gr.run(noHarmDone, "fetch", "-t", string(remoteUpstream), "master")
175175
if err != nil {
176176
// Handle if repo is not a fork
177-
gr.run(noHarmDone, "fetch", "-t", "master")
177+
_, err = gr.run(noHarmDone, "fetch", "-t", "master")
178+
if err != nil {
179+
_ = fmt.Errorf("failed to fetch tags from master")
180+
}
178181
}
179182

180183
gr.comment("loading remote tags")
@@ -364,16 +367,16 @@ func (gr *Runner) GetLatestTag(releaseBranch string) (string, error) {
364367
// Assuming release branch has this format: release-path/to/module-vX.Y.Z
365368
// and each release branch maintains tags, extract version from latest `releaseBranch`
366369
gr.comment("extract version from latest release branch")
367-
filteredBranchList, err := gr.run(noHarmDone, "branch", "-a", "--list", "*"+string(releaseBranch)+"*", "--sort=-committerdate")
370+
filteredBranchList, err := gr.run(noHarmDone, "branch", "-a", "--list", "*"+releaseBranch+"*", "--sort=-committerdate")
368371
if len(filteredBranchList) < 1 {
369-
fmt.Errorf("latest tag not found for %s", releaseBranch)
372+
_ = fmt.Errorf("latest tag not found for %s", releaseBranch)
370373
return "", err
371374
}
372375
newestBranch := strings.Split(strings.ReplaceAll(filteredBranchList, "\r\n", "\n"), "\n")
373376
split := strings.Split(newestBranch[0], "-")
374377
latestTag = split[len(split)-1]
375378
if err != nil {
376-
fmt.Errorf("error getting latest tag for %s: %q", releaseBranch, err.Error())
379+
_ = fmt.Errorf("error getting latest tag for %s", releaseBranch)
377380
}
378381

379382
return latestTag, nil

cmd/gorepomod/internal/utils/utils.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,34 @@ func SliceContains(slice []string, target string) bool {
5151
// Receive git remote url as input and produce string containing git repository name
5252
// e.g. kustomize, myrepo/kustomize
5353
func ParseGitRepositoryPath(urlString string) string {
54-
var d []string = getUrlStringArray(urlString)
54+
var d []string = getURLStringArray(urlString)
5555
protocol := d[0]
5656

5757
var repoPath string
5858

5959
// for ssh protocol git@github.com:path/repo.git
60-
if protocol == "git" {
60+
switch protocol {
61+
case "git":
6162
repoPath = strings.Join(d[2:len(d)-1], "/") + "/" + d[3][:len(d[3])-4]
6263
// https protocol https://github.com/path/repo.git
63-
} else if protocol == "https" {
64+
case "https":
6465
repoPath = strings.Join(d[2:], "/")
6566
repoPath = repoPath[:len(repoPath)-4]
6667
// unsupported format
6768
// TODO: confirm if we should handle other formats not commonly supported by Github
68-
} else {
69-
fmt.Errorf("protocol format is not supported: %s", protocol)
69+
default:
70+
_ = fmt.Errorf("protocol format is not supported: %s", protocol)
7071
return ""
7172
}
7273

7374
return d[1] + "/" + repoPath
7475
}
7576

7677
// Extract array of string from urlString
77-
func getUrlStringArray(urlString string) []string {
78+
func getURLStringArray(urlString string) []string {
7879
// Supported git regex based on URI allowed regex as defined under RFC3986
79-
re, err := regexp.Compile(`[A-Za-z0-9][A-Za-z0-9+.-]*`)
80-
if err != nil {
81-
fmt.Errorf("error when parsing regex: %q", err.Error())
82-
}
80+
const rfc3986 = `[A-Za-z0-9][A-Za-z0-9+.-]*`
81+
re := regexp.MustCompile(rfc3986)
8382
var u []string = re.FindAllString(urlString, -1)
8483
return u
8584
}

0 commit comments

Comments
 (0)