Skip to content

Commit

Permalink
fix(update): add the mark (*) to the current version
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Oct 15, 2023
1 parent 1c8772e commit 06a2913
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/generate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Controller struct {
}

type FuzzyGetter interface {
Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string
Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string
}

type FuzzyFinder interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (c *Controller) getOutputtedPkg(ctx context.Context, logE *logrus.Entry, pa
outputPkg.Registry = ""
}
if outputPkg.Version == "" {
version := c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, param.SelectVersion)
version := c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, "", param.SelectVersion)
if version == "" {
outputPkg.Version = "[SET PACKAGE VERSION]"
return outputPkg
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/update/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ConfigReader interface {
}

type FuzzyGetter interface {
Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string
Get(ctx context.Context, logE *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string
}

type RepositoriesService interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/update/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (c *Controller) getPackageNewVersion(ctx context.Context, logE *logrus.Entr
return ""
}
}
return c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, param.SelectVersion)
return c.fuzzyGetter.Get(ctx, logE, pkg.PackageInfo, pkg.Package.Version, param.SelectVersion)
}

func (c *Controller) selectPackages(logE *logrus.Entry, cfgFilePath string) (map[string]struct{}, error) {
Expand Down
20 changes: 17 additions & 3 deletions pkg/versiongetter/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package versiongetter

import (
"context"
"strings"

"github.com/aquaproj/aqua/v2/pkg/config/registry"
"github.com/aquaproj/aqua/v2/pkg/fuzzyfinder"
Expand Down Expand Up @@ -30,7 +31,7 @@ func NewMockFuzzyGetter(s string) *MockFuzzyGetter {
}
}

func (g *MockFuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string {
func (g *MockFuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string {
return g.s
}

Expand All @@ -39,7 +40,7 @@ type FuzzyFinder interface {
FindMulti(items []*fuzzyfinder.Item, hasPreview bool) ([]int, error)
}

func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, useFinder bool) string {
func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.PackageInfo, currentVersion string, useFinder bool) string { //nolint:cyclop
filters, err := createFilters(pkg)
if err != nil {
return ""
Expand All @@ -50,15 +51,28 @@ func (g *FuzzyGetter) Get(ctx context.Context, _ *logrus.Entry, pkg *registry.Pa
return ""
}

if useFinder {
if useFinder { //nolint:nestif
versions, err := versionGetter.List(ctx, pkg, filters)
if err != nil {
return ""
}
currentVersionIndex := 0
if currentVersion != "" {
for i, version := range versions {
if version.Item == currentVersion {
version.Item += " (*)"
currentVersionIndex = i
break
}
}
}
idx, err := g.fuzzyFinder.Find(versions, true)
if err != nil {
return ""
}
if idx == currentVersionIndex {
return strings.TrimSuffix(versions[idx].Item, " (*)")
}
return versions[idx].Item
}

Expand Down

0 comments on commit 06a2913

Please sign in to comment.