Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app-catalog/src/api/charts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,32 @@ export function fetchChartValues(packageID: string, packageVersion: string) {
},
}).then(response => response.text());
}

export async function fetchLatestAppVersion(chartName: string): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one needs docs.

if (!chartName) {
return '—';
}

try {
const url = new URL('https://artifacthub.io/api/v1/packages/search');
url.searchParams.set('offset', '0');
url.searchParams.set('limit', '5');
url.searchParams.set('facets', 'false');
url.searchParams.set('kind', '0');
url.searchParams.set('ts_query_web', chartName);

const response = await fetch(url.toString());
const dataResponse = await response.json();
const packages: any[] = dataResponse?.packages ?? [];

const lowerChartName = chartName.toLowerCase();
const selectedPackage =
packages.find(
p => p?.name?.toLowerCase() === lowerChartName || p?.normalized_name === lowerChartName
) ?? packages[0];
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback to packages[0] could return the wrong package if no exact match is found. This may display incorrect version information for applications that don't have an exact name match in ArtifactHub.

Suggested change
) ?? packages[0];
);

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one seems a valid point?


return selectedPackage?.app_version ?? '—';
} catch {
return '—';
}
}
35 changes: 33 additions & 2 deletions app-catalog/src/components/releases/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ import {
} from '@kinvolk/headlamp-plugin/lib/CommonComponents';
import { Box } from '@mui/material';
import { useEffect, useState } from 'react';
import { fetchLatestAppVersion } from '../../api/charts';
import { listReleases } from '../../api/releases';

const formatVersion = (v?: string) => {
const s = (v ?? '').trim();

if (!s || s === '—') {
return '—';
}

return s.startsWith('v') ? s : `v${s}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add a v to it if it's not there. Some version numbers don't use v in there, so adding it could be confusing to people.

};

export default function ReleaseList({ fetchReleases = listReleases }) {
const [releases, setReleases] = useState<Array<any> | null>(null);
const [latestMap, setLatestMap] = useState<Record<string, string>>({});

useEffect(() => {
fetchReleases().then(response => {
Expand All @@ -23,6 +35,21 @@ export default function ReleaseList({ fetchReleases = listReleases }) {
});
}, []);

useEffect(() => {
if (!releases?.length) {
setLatestMap({});
return;
}

Promise.all(
releases.map(async r => {
const chartName = r?.chart?.metadata?.name;
const v = chartName ? await fetchLatestAppVersion(chartName).catch(() => '—') : '—';
return [r.name, v] as const;
})
Comment on lines +38 to +49
Copy link

Copilot AI Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation makes parallel API calls for each release without any rate limiting or batching. Consider adding a delay between requests or implementing batching to avoid overwhelming the ArtifactHub API, especially with large numbers of installed applications.

Suggested change
useEffect(() => {
if (!releases?.length) {
setLatestMap({});
return;
}
Promise.all(
releases.map(async r => {
const chartName = r?.chart?.metadata?.name;
const v = chartName ? await fetchLatestAppVersion(chartName).catch(() => '—') : '—';
return [r.name, v] as const;
})
// Helper to batch promises
async function batchPromises<T, R>(items: T[], batchSize: number, fn: (item: T) => Promise<R>): Promise<R[]> {
const results: R[] = [];
for (let i = 0; i < items.length; i += batchSize) {
const batch = items.slice(i, i + batchSize);
const batchResults = await Promise.all(batch.map(fn));
results.push(...batchResults);
}
return results;
}
useEffect(() => {
if (!releases?.length) {
setLatestMap({});
return;
}
// Limit to 5 concurrent requests per batch
batchPromises(
releases,
5,
async r => {
const chartName = r?.chart?.metadata?.name;
const v = chartName ? await fetchLatestAppVersion(chartName).catch(() => '—') : '—';
return [r.name, v] as const;
}

Copilot uses AI. Check for mistakes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems valid too?

It looks like the exact rate limits are not documented: https://artifacthub.io/docs/topics/faq/#what-are-the-api-rate-limits

I guess 100+ charts is not uncommon.

).then(entries => setLatestMap(Object.fromEntries(entries)));
}, [releases]);

return (
<SectionBox title="Installed" textAlign="center" paddingTop={2}>
<SimpleTable
Expand Down Expand Up @@ -56,8 +83,12 @@ export default function ReleaseList({ fetchReleases = listReleases }) {
getter: release => release.namespace,
},
{
label: 'App Version',
getter: release => release.chart.metadata.appVersion,
label: 'Current Version',
getter: release => formatVersion(release.chart.metadata.appVersion),
},
{
label: 'Latest Version',
getter: release => formatVersion(latestMap[release?.name]),
},
{
label: 'Version',
Expand Down
Loading