fix: Resolve repository URL for install/update (registry + install fallbacks)
This commit is contained in:
@@ -137,17 +137,13 @@ func GetRegistry(w http.ResponseWriter, r *http.Request) {
|
||||
pkgNameLower := strings.ToLower(pkg.Name)
|
||||
imageRef := fmt.Sprintf("git.dcntrlized.org/%s/%s:%s", ociOrg, pkgNameLower, pkg.Version)
|
||||
|
||||
// Default fallback source from Gitea REST API
|
||||
source := pkg.HTMLURL
|
||||
if pkg.Repository != nil && pkg.Repository.HTMLURL != "" {
|
||||
source = pkg.Repository.HTMLURL
|
||||
}
|
||||
|
||||
// The Gitea package API does not link org-level container packages to a
|
||||
// repository, so the repository URL is resolved from the image's OCI
|
||||
// labels below, or derived from the image reference as a last resort.
|
||||
item := types.RegistryContainer{
|
||||
Name: pkg.Name,
|
||||
Version: normalizeSemver(pkg.Version),
|
||||
Image: imageRef,
|
||||
Source: source,
|
||||
CreatedAt: pkg.CreatedAt,
|
||||
}
|
||||
|
||||
@@ -240,6 +236,17 @@ func GetRegistry(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
// Resolve the source repository URL: OCI source label if present, else
|
||||
// derived from the image reference (host/org/repo).
|
||||
if item.Source == "" {
|
||||
item.Source = repoURLFromImageRef(imageRef)
|
||||
}
|
||||
// The compose file is fetched from the git repository, so fall back to
|
||||
// the resolved source URL when the OCI url label is absent.
|
||||
if item.URL == "" {
|
||||
item.URL = item.Source
|
||||
}
|
||||
|
||||
registryItems = append(registryItems, item)
|
||||
}
|
||||
|
||||
@@ -248,3 +255,13 @@ func GetRegistry(w http.ResponseWriter, r *http.Request) {
|
||||
logger.Error("Failed to write response: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// repoURLFromImageRef derives the repository browse URL from a container image
|
||||
// reference of the form host/org/repo:tag (https://host/org/repo).
|
||||
func repoURLFromImageRef(imageRef string) string {
|
||||
ref, err := name.ParseReference(imageRef)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return "https://" + ref.Context().RegistryStr() + "/" + ref.Context().RepositoryStr()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user