Skip to content

Commit

Permalink
refactor code to pass linting
Browse files Browse the repository at this point in the history
  • Loading branch information
antoooks committed Dec 7, 2023
1 parent 00589be commit 5335512
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions cmd/gorepomod/internal/edit/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (e *Editor) Pin(target misc.LaModule, oldV, newV semver.SemVer) error {
"-require=sigs.k8s.io/kustomize/"+string(target.ShortName())+"@"+newV.String(),
)
if err != nil {
return err
return fmt.Errorf("%w", err)
}
return e.run("tidy")
}
Expand All @@ -81,7 +81,7 @@ func (e *Editor) UnPin(target misc.LaModule, oldV semver.SemVer) error {
"-replace="+r.String(),
)
if err != nil {
return err
return fmt.Errorf("%w", err)
}
return e.run("tidy")
}
7 changes: 5 additions & 2 deletions cmd/gorepomod/internal/git/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,12 @@ func (gr *Runner) FetchRemote(remote misc.TrackedRepo) error {
err := gr.runNoOut(noHarmDone, "fetch", string(remote))
if err != nil {
// If current repo is fork
return gr.runNoOut(noHarmDone, "fetch", string(remoteUpstream))
err = gr.runNoOut(noHarmDone, "fetch", string(remoteUpstream))
if err != nil {
return fmt.Errorf("%w", err)
}
}
return err
return fmt.Errorf("%w", err)
}

// MergeFromRemoteMain does a fast forward only merge with main branch.
Expand Down
8 changes: 3 additions & 5 deletions cmd/gorepomod/internal/repo/dotgitdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (dg *DotGitData) AbsPath() string {
// ~/gopath/src/sigs.k8s.io/kustomize
// ~/gopath/src/github.com/monopole/gorepomod
func NewDotGitDataFromPath(path string, localFlag bool) (*DotGitData, error) {

if !utils.DirExists(filepath.Join(path, dotGitFileName)) {
return nil, fmt.Errorf(
"%q doesn't have a %q file", path, dotGitFileName)
Expand Down Expand Up @@ -89,7 +88,6 @@ func NewDotGitDataFromPath(path string, localFlag bool) (*DotGitData, error) {
repoPath: path[index+len(srcHint):],
}, nil
}

}

// It's a factory factory.
Expand Down Expand Up @@ -187,17 +185,17 @@ func (dg *DotGitData) checkModulesLocal(modules []*protoModule) error {
func getLocalPrefix(dgAbsPath string) string {
_, err := os.Stat(dgAbsPath + ".git")
if err != nil {
fmt.Errorf(".git directory does not exist int path %q", dgAbsPath)
_ = fmt.Errorf(".git directory does not exist int path %w", dgAbsPath)

Check failure on line 188 in cmd/gorepomod/internal/repo/dotgitdata.go

View workflow job for this annotation

GitHub Actions / Lint

printf: fmt.Errorf format %w has arg dgAbsPath of wrong type string (govet)
}

out, err := exec.Command("git", "config", "--get", "remote.origin.url").Output()
if err != nil {
fmt.Errorf("failed extracting git information: %q", err.Error())
_ = fmt.Errorf("failed extracting git information: %w", err.Error())

Check failure on line 193 in cmd/gorepomod/internal/repo/dotgitdata.go

View workflow job for this annotation

GitHub Actions / Lint

printf: fmt.Errorf format %w has arg err.Error() of wrong type string (govet)
}

localPrefix := utils.ParseGitRepositoryPath(string(out))
if len(localPrefix) == 0 {
fmt.Errorf("parsed git repository path is empty: %q", err.Error())
_ = fmt.Errorf("parsed git repository path is empty: %w", err.Error())

Check failure on line 198 in cmd/gorepomod/internal/repo/dotgitdata.go

View workflow job for this annotation

GitHub Actions / Lint

printf: fmt.Errorf format %w has arg err.Error() of wrong type string (govet)
}
return localPrefix
}
3 changes: 1 addition & 2 deletions cmd/gorepomod/internal/repo/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (mgr *Manager) List() error {
gr := git.NewQuiet(mgr.AbsPath(), false, false)
for _, module := range mgr.modules {
releaseBranch := fmt.Sprintf("release-%s", module.ShortName())
_, err := gr.GetLatestTag(string(releaseBranch))
_, err := gr.GetLatestTag(releaseBranch)
if err != nil {
fmt.Errorf("failed getting latest tags for %s", module)

Check failure on line 89 in cmd/gorepomod/internal/repo/manager.go

View workflow job for this annotation

GitHub Actions / Lint

unusedresult: result of fmt.Errorf call not used (govet)
}
Expand Down Expand Up @@ -134,7 +134,6 @@ func (mgr *Manager) Debug(_ misc.LaModule, doIt bool, localFlag bool) error {
// * Each minor release gets its own branch.
func (mgr *Manager) Release(
target misc.LaModule, bump semver.SvBump, doIt bool, localFlag bool) error {

if reps := target.GetDisallowedReplacements(
mgr.allowedReplacements); len(reps) > 0 {
return fmt.Errorf(
Expand Down
31 changes: 18 additions & 13 deletions cmd/gorepomod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,43 +76,48 @@ func actualMain() error {
v := args.Version()
// Update branch history
gr := git.NewQuiet(mgr.AbsPath(), args.DoIt(), false)
gr.FetchRemote(misc.TrackedRepo(gr.GetMainBranch()))
err = gr.FetchRemote(misc.TrackedRepo(gr.GetMainBranch()))
if err != nil {
return err

Check failure on line 81 in cmd/gorepomod/main.go

View workflow job for this annotation

GitHub Actions / Lint

error returned from external package is unwrapped: sig: func (*sigs.k8s.io/kustomize/cmd/gorepomod/internal/git.Runner).FetchRemote(remote sigs.k8s.io/kustomize/cmd/gorepomod/internal/misc.TrackedRepo) error (wrapcheck)
}

if v.IsZero() {
// Always use latest tag while does not removing manual usage capability
releaseBranch := fmt.Sprintf("release-%s", targetModule.ShortName())
fmt.Printf("new version not specified, fall back to latest version according to release branch: %s-*\n", releaseBranch)
latest, err := gr.GetLatestTag(string(releaseBranch))
latest, err := gr.GetLatestTag(releaseBranch)
if err != nil {
fmt.Errorf("cannot get latest tag for %s, falling back to local version %s", targetModule.ShortName(), targetModule.VersionLocal())
v = targetModule.VersionLocal()
return mgr.Pin(args.DoIt(), targetModule, v)

err = mgr.Pin(args.DoIt(), targetModule, v)
return fmt.Errorf("%w", err)
}
v, err = semver.Parse(latest)
if err != nil {
fmt.Errorf("failed to parse value for %s, falling back to local version %s", latest, targetModule.VersionLocal())
v = targetModule.VersionLocal()
return mgr.Pin(args.DoIt(), targetModule, v)
err = mgr.Pin(args.DoIt(), targetModule, v)
return fmt.Errorf("%w", err)
}
}

// If we can't find revision extracted from latest version specified on release branch
err = mgr.Pin(args.DoIt(), targetModule, v)
if err != nil {
fmt.Errorf("cannot determine latest version existence, retrying with local version %s", targetModule.VersionLocal())
v = targetModule.VersionLocal()
err = mgr.Pin(args.DoIt(), targetModule, v)
}
return err
return fmt.Errorf("%w", err)
case arguments.UnPin:
return mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
err = mgr.UnPin(args.DoIt(), targetModule, conditionalModule)
return fmt.Errorf("%w", err)
case arguments.Release:
return mgr.Release(targetModule, args.Bump(), args.DoIt(), args.LocalFlag())
err = mgr.Release(targetModule, args.Bump(), args.DoIt(), args.LocalFlag())
return fmt.Errorf("%w", err)
case arguments.UnRelease:
return mgr.UnRelease(targetModule, args.DoIt(), args.LocalFlag())
err = mgr.UnRelease(targetModule, args.DoIt(), args.LocalFlag())
return fmt.Errorf("%w", err)
case arguments.Debug:
return mgr.Debug(targetModule, args.DoIt(), args.LocalFlag())
err = mgr.Debug(targetModule, args.DoIt(), args.LocalFlag())
return fmt.Errorf("%w", err)
default:
return fmt.Errorf("cannot handle cmd %v", args.GetCommand())
}
Expand Down

0 comments on commit 5335512

Please sign in to comment.