Skip to content

Commit

Permalink
fix: fix the default value of files[].name
Browse files Browse the repository at this point in the history
If the package has a name field, the name is split with "/" and the last element is used as the default file name.
  • Loading branch information
suzuki-shunsuke committed Jan 3, 2023
1 parent b9d12ae commit 0fe5661
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
33 changes: 20 additions & 13 deletions pkg/config/registry/package_info.go
Expand Up @@ -3,6 +3,7 @@ package registry
import (
"fmt"
"path"
"strings"

"github.com/aquaproj/aqua/pkg/runtime"
"github.com/iancoleman/orderedmap"
Expand Down Expand Up @@ -409,28 +410,34 @@ func (pkgInfo *PackageInfo) GetFiles() []*File {
if len(pkgInfo.Files) != 0 {
return pkgInfo.Files
}
if pkgInfo.HasRepo() {

if cmdName := pkgInfo.getDefaultCmdName(); cmdName != "" {
return []*File{
{
Name: pkgInfo.RepoName,
Name: cmdName,
},
}
}
return pkgInfo.Files
}

func (pkgInfo *PackageInfo) getDefaultCmdName() string {
if pkgInfo.HasRepo() {
if pkgInfo.Name == "" {
return pkgInfo.RepoName
}
if i := strings.LastIndex(pkgInfo.Name, "/"); i != -1 {
return pkgInfo.Name[i+1:]
}
return pkgInfo.Name
}
if pkgInfo.Type == PkgInfoTypeGoInstall {
if pkgInfo.Asset != nil {
return []*File{
{
Name: *pkgInfo.Asset,
},
}
}
return []*File{
{
Name: path.Base(pkgInfo.GetPath()),
},
return *pkgInfo.Asset
}
return path.Base(pkgInfo.GetPath())
}
return pkgInfo.Files
return ""
}

func (pkgInfo *PackageInfo) SLSASourceURI() string {
Expand Down
16 changes: 15 additions & 1 deletion pkg/config/registry/package_info_test.go
Expand Up @@ -207,7 +207,7 @@ func TestPackageInfo_GetReplacements(t *testing.T) {
}
}

func TestPackageInfo_GetFiles(t *testing.T) {
func TestPackageInfo_GetFiles(t *testing.T) { //nolint:funlen
t.Parallel()
data := []struct {
title string
Expand Down Expand Up @@ -248,6 +248,20 @@ func TestPackageInfo_GetFiles(t *testing.T) {
RepoName: "ci-info",
},
},
{
title: "has name",
exp: []*registry.File{
{
Name: "cmctl",
},
},
pkgInfo: &registry.PackageInfo{
Type: "github_release",
RepoOwner: "cert-manager",
RepoName: "cert-manager",
Name: "cert-manager/cert-manager/cmctl",
},
},
}
for _, d := range data {
d := d
Expand Down

0 comments on commit 0fe5661

Please sign in to comment.