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

Add default values for required fields in artifacthub-pkg #555

Merged
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions utils/catalog/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"regexp"
"strings"

"github.com/layer5io/meshkit/models/catalog/v1alpha1"
)

func BuildArtifactHubPkg(name, downloadURL, user, version, createdAt string, catalogData *v1alpha1.CatalogData) *ArtifactHubMetadata {
artifacthubPkg := &ArtifactHubMetadata{
Name: toKebabCase(name),
DisplayName: name,
Description: catalogData.PatternInfo,
Description: valueOrElse(catalogData.PatternInfo, "A Meshery Design"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really helpful. 👏

Provider: Provider{
Name: user,
},
Expand All @@ -26,7 +27,7 @@ func BuildArtifactHubPkg(name, downloadURL, user, version, createdAt string, cat
},
},
HomeURL: "https://docs.meshery.io/concepts/logical/designs",
Version: version,
Version: valueOrElse(version, "0.0.1"),
CreatedAt: createdAt,
License: "Apache-2.0",
LogoURL: "https://raw.githubusercontent.com/meshery/meshery.io/0b8585231c6e2b3251d38f749259360491c9ee6b/assets/images/brand/meshery-logo.svg",
Expand Down Expand Up @@ -56,6 +57,14 @@ func BuildArtifactHubPkg(name, downloadURL, user, version, createdAt string, cat
return artifacthubPkg
}

func valueOrElse(s string, fallback string) string {
if len(s) == 0 {
return fallback
} else {
return s
}
}

func toKebabCase(s string) string {
s = strings.ToLower(s)
re := regexp.MustCompile(`\s+`)
Expand Down
Loading