Skip to content

[model] Allow Random Model Names for Artifact Hub Registrant #722

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 18 additions & 3 deletions generators/artifacthub/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package artifacthub

import (
"fmt"
"net/url"

"github.com/layer5io/meshkit/generators/models"
)
Expand All @@ -12,13 +13,27 @@ type ArtifactHubPackageManager struct {
}

func (ahpm ArtifactHubPackageManager) GetPackage() (models.Package, error) {
// get relevant packages
pkgs, err := GetAhPackagesWithName(ahpm.PackageName)
// Try to extract package name from URL if available
searchName := ahpm.PackageName
if ahpm.SourceURL != "" {
// Try to parse the URL
parsedURL, err := url.Parse(ahpm.SourceURL)
if err == nil {
// Extract the ts_query_web parameter if it exists
queryParams := parsedURL.Query()
if tsQueryWeb := queryParams.Get("ts_query_web"); tsQueryWeb != "" {
searchName = tsQueryWeb
}
}
}
Comment on lines +20 to +28
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding a more robust error handling mechanism here. Currently, if url.Parse fails, the code silently continues using the original package name. It might be beneficial to log the error or provide a more explicit fallback mechanism. What do you think about adding a log here?


// get relevant packages with either the extracted name or original name
pkgs, err := GetAhPackagesWithName(searchName)
if err != nil {
return nil, err
}
if len(pkgs) == 0 {
return nil, ErrNoPackageFound(ahpm.PackageName, "Artifacthub")
return nil, ErrNoPackageFound(searchName, "Artifacthub")
Comment on lines 35 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Consider adding the original package name to the error message for better context. This would help users understand if the issue is with the extracted name or the original name. For example, the error message could be updated to: ErrNoPackageFound(searchName, ahpm.PackageName, "Artifacthub")

return nil, ErrNoPackageFound(searchName, ahpm.PackageName, "Artifacthub")

}
// update package information
for i, ap := range pkgs {
Expand Down
Loading