Refactor package types to use dedicated schema types per package type (NPM, PyPI, NuGet, OCI, MCPB) (#634)

This commit is contained in:
Radoslav Dimitrov 2025-10-11 10:53:45 +03:00 • committed by GitHub
commit 632cbce815
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -27,23 +27,20 @@ func ValidateMCPB(ctx context.Context, pkg model.Package, _ string) error {
return ErrMissingIdentifierForMCPB
}
// Validate that old format fields are not present
// MCPB packages use URL in identifier, version is embedded in the URL
if pkg.Version != "" {
return fmt.Errorf("MCPB packages must not have 'version' field - version should be embedded in the download URL")
}
if pkg.RegistryBaseURL != "" {
return fmt.Errorf("MCPB packages must not have 'registryBaseUrl' field - use the full download URL in 'identifier' instead")
}
err := validateMCPBUrl(pkg.Identifier)
if err != nil {
return err
}
inferredBaseURL, err := inferMCPBRegistryBaseURL(pkg.Identifier)
if err != nil {
return err
}
if pkg.RegistryBaseURL == "" {
pkg.RegistryBaseURL = inferredBaseURL
} else if pkg.RegistryBaseURL != inferredBaseURL {
return fmt.Errorf("MCPB package '%s' has inconsistent registry base URL: %s (expected: %s)",
pkg.Identifier, pkg.RegistryBaseURL, inferredBaseURL)
}
// Parse the URL to validate format
url, err := url.Parse(pkg.Identifier)
if err != nil {
@ -161,21 +158,3 @@ func isValidGitLabReleaseURL(path string) bool {
return false
}
// inferMCPBRegistryBaseURL infers the registry base URL from an MCPB identifier
func inferMCPBRegistryBaseURL(identifier string) (string, error) {
parsedURL, err := url.Parse(identifier)
if err != nil {
return "", err
}
host := strings.ToLower(parsedURL.Host)
switch host {
case "github.com", "www.github.com":
return model.RegistryURLGitHub, nil
case "gitlab.com", "www.gitlab.com":
return model.RegistryURLGitLab, nil
default:
return "", fmt.Errorf("invalid host for MCPB package: %s, expected github or gitlab", host)
}
}