Skip to content

Commit

Permalink
fix(generate-registry): format description of cargo packages (#3307)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke authored Nov 30, 2024
1 parent a5b82cd commit ae39729
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
34 changes: 22 additions & 12 deletions pkg/controller/generate-registry/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,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)
if len(param.Commands) != 0 {
files := make([]*registry.File, len(param.Commands))
for i, cmd := range param.Commands {
files[i] = &registry.File{
Name: cmd,
}
}
pkgInfo.Files = files
}
pkgInfo, versions := c.getPackageInfo(ctx, logE, pkgName, param)
if param.OutTestData != "" {
if err := c.testdataOutputter.Output(&output.Param{
List: listPkgsFromVersions(pkgName, versions),
Expand Down Expand Up @@ -80,7 +71,26 @@ 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 cleanDescription(desc string) string {
return strings.TrimRight(strings.TrimSpace(gomoji.RemoveEmojis(desc)), ".!?")
}

func (c *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry, arg string, param *config.Param) (*registry.PackageInfo, []string) {
pkgInfo, versions := c.getPackageInfoMain(ctx, logE, arg, param.Limit)
pkgInfo.Description = cleanDescription(pkgInfo.Description)
if len(param.Commands) != 0 {
files := make([]*registry.File, len(param.Commands))
for i, cmd := range param.Commands {
files[i] = &registry.File{
Name: cmd,
}
}
pkgInfo.Files = files
}
return pkgInfo, versions
}

func (c *Controller) getPackageInfoMain(ctx context.Context, logE *logrus.Entry, arg string, limit int) (*registry.PackageInfo, []string) {
pkgName, version, _ := strings.Cut(arg, "@")
if strings.HasPrefix(pkgName, "crates.io/") {
return c.getCargoPackageInfo(ctx, logE, pkgName)
Expand All @@ -105,7 +115,7 @@ func (c *Controller) getPackageInfo(ctx context.Context, logE *logrus.Entry, arg
"repo_name": pkgInfo.RepoName,
}).WithError(err).Warn("get the repository")
} else {
pkgInfo.Description = strings.TrimRight(strings.TrimSpace(gomoji.RemoveEmojis(repo.GetDescription())), ".!?")
pkgInfo.Description = repo.GetDescription()
}
if limit != 1 && version == "" {
return c.getPackageInfoWithVersionOverrides(ctx, logE, pkgName, pkgInfo, limit)
Expand Down
5 changes: 3 additions & 2 deletions 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 @@ -114,7 +115,7 @@ func TestController_getPackageInfo(t *testing.T) { //nolint:funlen
RepoName: "skim",
Type: "cargo",
Crate: "skim",
Description: "Fuzzy Finder in rust!",
Description: "Fuzzy Finder in rust",
},
crate: &cargo.CratePayload{
Crate: &cargo.Crate{
Expand All @@ -139,7 +140,7 @@ 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{})
if diff := cmp.Diff(d.exp, pkgInfo); diff != "" {
t.Fatal(diff)
}
Expand Down

0 comments on commit ae39729

Please sign in to comment.