diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index f0daeecf..2ef78880 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -79,7 +79,7 @@ func (pkg AhPackage) GenerateComponents(group string) ([]_component.ComponentDef comp.Model.Metadata.AdditionalProperties = make(map[string]interface{}) } comp.Model.Metadata.AdditionalProperties["source_uri"] = pkg.ChartUrl - comp.Model.Version = pkg.Version + comp.Model.Version = pkg.sanitizedVersion() comp.Model.Name = pkg.Name comp.Model.Category = category.CategoryDefinition{ Name: "", @@ -143,6 +143,10 @@ func (pkg *AhPackage) Validator() { } +func (pkg AhPackage) sanitizedVersion() string { + return strings.TrimPrefix(pkg.Version, "v") +} + // GetAllAhHelmPackages returns a list of all AhPackages and is super slow to avoid rate limits. func GetAllAhHelmPackages() ([]AhPackage, error) { pkgs := make([]AhPackage, 0) diff --git a/generators/artifacthub/package_test.go b/generators/artifacthub/package_test.go index 34b24938..1b1a6401 100644 --- a/generators/artifacthub/package_test.go +++ b/generators/artifacthub/package_test.go @@ -71,3 +71,27 @@ func TestGetChartUrl(t *testing.T) { }) } } + +func TestVersionSanitization(t *testing.T) { + tests := []struct { + name string + input string + expected string + }{ + {"With v prefix", "v1.2.3", "1.2.3"}, + {"Without v prefix", "1.2.3", "1.2.3"}, + {"Date based", "v2022.06.14", "2022.06.14"}, + {"Empty", "", ""}, + {"Complex", "v1.0.0-beta+exp.sha.5114f85", "1.0.0-beta+exp.sha.5114f85"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pkg := AhPackage{Version: tt.input} + // This calls the helper method we added to package.go + if got := pkg.sanitizedVersion(); got != tt.expected { + t.Errorf("sanitizedVersion() = %v, want %v", got, tt.expected) + } + }) + } +}