From 796025c34540fe496937041565640d00b86b30c7 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 24 Oct 2023 16:55:00 +0200 Subject: [PATCH] catalog-cd: fix generate-catalog If the repository has no name, use the last part of the URL to define its name. Signed-off-by: Vincent Demeester --- internal/catalog/catalog.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/catalog/catalog.go b/internal/catalog/catalog.go index 256bd9ab..202784da 100644 --- a/internal/catalog/catalog.go +++ b/internal/catalog/catalog.go @@ -19,7 +19,10 @@ func FetchFromExternals(e config.External, client *api.RESTClient) (Catalog, err Resources: map[string]Resource{}, } for _, r := range e.Repositories { - fmt.Fprintln(os.Stderr, "Fetching", r.Name, "("+r.URL+")") + if r.Name == "" { + // Name is empty, take the last part of the URL + r.Name = filepath.Base(r.URL) + } c.Resources[r.Name] = Resource{} m, err := fetcher.FetchContractsFromRepository(r, client) @@ -33,7 +36,7 @@ func FetchFromExternals(e config.External, client *api.RESTClient) (Catalog, err } } - for version, _ := range m { + for version := range m { resourcesDownloaldURI := fmt.Sprintf("%s/releases/download/%s/%s", r.URL, version, "resources.tar.gz") c.Resources[r.Name][version] = resourcesDownloaldURI } @@ -43,7 +46,7 @@ func FetchFromExternals(e config.External, client *api.RESTClient) (Catalog, err func GenerateFilesystem(path string, c Catalog) error { for name, resource := range c.Resources { - fmt.Fprintf(os.Stderr, "# Fetching resource %s\n", name) + fmt.Fprintf(os.Stderr, "# Fetching resources from %s\n", name) for version, uri := range resource { fmt.Fprintf(os.Stderr, "## Fetching version %s\n", version) if err := fetchAndExtract(path, uri, version); err != nil { @@ -106,7 +109,7 @@ func untar(dst, version string, r io.Reader) error { // if its a dir and it doesn't exist create it case tar.TypeDir: if _, err := os.Stat(target); err != nil { - if err := os.MkdirAll(target, 0755); err != nil { + if err := os.MkdirAll(target, 0o755); err != nil { return err } }