Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(generate-reigstry): add an option "type" #2361

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/cli/generate_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func (r *Runner) newGenerateRegistryCommand() *cli.Command {
// Name: "i",
// Usage: "Insert a registry to configuration file",
// },
&cli.StringFlag{
Name: "type",
Aliases: []string{"t"},
Usage: "package type",
Value: "github_release",
},
&cli.StringFlag{
Name: "out-testdata",
Usage: "A file path where the testdata is outputted",
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (r *Runner) setParam(c *cli.Context, commandName string, param *config.Para
param.ConfigFilePath = c.String("config")
param.Dest = c.String("o")
param.OutTestData = c.String("out-testdata")
param.Type = c.String("type")
param.OnlyLink = c.Bool("only-link")
if commandName == "generate-registry" {
param.InsertFile = c.String("i")
Expand Down
1 change: 1 addition & 0 deletions pkg/config/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ type Param struct {
Dest string
HomeDir string
OutTestData string
Type string
Limit int
MaxParallelism int
Args []string
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/generate-registry/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *Controller) GenerateRegistry(ctx context.Context, param *config.Param,
}

func (c *Controller) genRegistry(ctx context.Context, param *config.Param, logE *logrus.Entry, pkgName string) error {
pkgInfo, versions := c.getPackageInfo(ctx, logE, pkgName, param.Limit)
pkgInfo, versions := c.getPackageInfo(ctx, logE, pkgName, param)
if len(param.Commands) != 0 {
files := make([]*registry.File, len(param.Commands))
for i, cmd := range param.Commands {
Expand Down Expand Up @@ -106,14 +106,14 @@ func (c *Controller) getRelease(ctx context.Context, repoOwner, repoName, versio
return release, err //nolint:wrapcheck
}

func (c *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry, arg string, limit int) (*registry.PackageInfo, []string) {
func (c *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry, arg string, param *config.Param) (*registry.PackageInfo, []string) {
pkgName, version, _ := strings.Cut(arg, "@")
if strings.HasPrefix(pkgName, "crates.io/") {
return c.getCargoPackageInfo(ctx, logE, pkgName)
}
splitPkgNames := strings.Split(pkgName, "/")
pkgInfo := &registry.PackageInfo{
Type: "github_release",
Type: param.Type,
}
if len(splitPkgNames) == 1 {
pkgInfo.Name = pkgName
Expand All @@ -133,8 +133,8 @@ func (c *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry, arg
} else {
pkgInfo.Description = strings.TrimRight(strings.TrimSpace(gomoji.RemoveEmojis(repo.GetDescription())), ".!?")
}
if limit != 1 && version == "" {
return c.getPackageInfoWithVersionOverrides(ctx, logE, pkgName, pkgInfo, limit)
if param.Limit != 1 && version == "" {
return c.getPackageInfoWithVersionOverrides(ctx, logE, pkgName, pkgInfo, param.Limit)
}
release, err := c.getRelease(ctx, pkgInfo.RepoOwner, pkgInfo.RepoName, version)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/generate-registry/generate_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"testing"

"github.com/aquaproj/aqua/v2/pkg/cargo"
"github.com/aquaproj/aqua/v2/pkg/config"
"github.com/aquaproj/aqua/v2/pkg/config/registry"
"github.com/aquaproj/aqua/v2/pkg/github"
"github.com/aquaproj/aqua/v2/pkg/ptr"
Expand Down Expand Up @@ -137,7 +138,10 @@ func TestController_getPackageInfo(t *testing.T) { //nolint:funlen
CratePayload: d.crate,
}
ctrl := NewController(nil, gh, nil, cargoClient)
pkgInfo, _ := ctrl.getPackageInfo(ctx, logE, d.pkgName, 0)
pkgInfo, _ := ctrl.getPackageInfo(ctx, logE, d.pkgName, &config.Param{
Type: "github_release",
Deep: true,
})
if diff := cmp.Diff(d.exp, pkgInfo); diff != "" {
t.Fatal(diff)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/generate-registry/version_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *Controller) getPackageInfoWithVersionOverrides(ctx context.Context, log
pkgs := make([]*Package, 0, len(releases))
for _, release := range releases {
pkgInfo := &registry.PackageInfo{
Type: "github_release",
Type: pkgInfo.Type,
RepoOwner: pkgInfo.RepoOwner,
RepoName: pkgInfo.RepoName,
}
Expand Down