Skip to content

Commit

Permalink
feat(resolve): several links can be available, so do not update only …
Browse files Browse the repository at this point in the history
…self but the others as well
  • Loading branch information
benoitf committed Jun 3, 2021
1 parent 0394221 commit 89e9d05
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/services/registry/devfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ function resolveIconUrl(metadata: che.DevfileMetaData, baseUrl: string): string
return createURL(metadata.icon, baseUrl).href;
}

function resolveLinkSelf(metadata: che.DevfileMetaData, baseUrl: string): string {
if (metadata.links.self.startsWith('http')) {
return metadata.links.self;
}

return createURL(metadata.links.self, baseUrl).href;
function resolveLinks(metadata: che.DevfileMetaData, baseUrl: string): any {
const resolvedLinks = {};
const linkNames = Object.keys(metadata.links);
linkNames.map(linkName => {
let updatedLink = metadata.links[linkName];
if (!updatedLink.startsWith('http')) {
updatedLink = createURL(updatedLink, baseUrl).href;
}
resolvedLinks[linkName] = updatedLink;
});
return resolvedLinks;
}

export async function fetchRegistryMetadata(registryUrl: string): Promise<che.DevfileMetaData[]> {
Expand All @@ -51,7 +56,7 @@ export async function fetchRegistryMetadata(registryUrl: string): Promise<che.De

return response.data.map(meta => {
meta.icon = resolveIconUrl(meta, registryUrl);
meta.links.self = resolveLinkSelf(meta, registryUrl);
meta.links = resolveLinks(meta, registryUrl);
return meta;
});
} catch (e) {
Expand Down

0 comments on commit 89e9d05

Please sign in to comment.