-
Notifications
You must be signed in to change notification settings - Fork 124
[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
base: master
Are you sure you want to change the base?
Changes from all commits
0b2e5d4
9eb7eeb
8348c0a
ba10271
f21c79f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ package artifacthub | |
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/layer5io/meshkit/generators/models" | ||
) | ||
|
@@ -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 | ||
} | ||
} | ||
} | ||
|
||
// 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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: return nil, ErrNoPackageFound(searchName, ahpm.PackageName, "Artifacthub") |
||
} | ||
// update package information | ||
for i, ap := range pkgs { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?