Skip to content

Commit

Permalink
Add default values for required fields in artifacthub-pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Chris C <[email protected]>
  • Loading branch information
ctcarrier committed Aug 9, 2024
1 parent ca535ba commit 010e2b5
Showing 1 changed file with 11 additions and 2 deletions.
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"),
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

0 comments on commit 010e2b5

Please sign in to comment.