From e28afd2c6c22fe11dbc9270f84b67dba9a1d4c07 Mon Sep 17 00:00:00 2001 From: Cannon Lock Date: Mon, 2 Dec 2024 16:28:31 -0600 Subject: [PATCH] Update Install Page components --- components/DownloadsComponent.tsx | 2 +- components/ReleasesTable.tsx | 2 +- utils/fetchReleases.tsx | 18 ++++++++++++++--- utils/utils.ts | 32 ++++++++++++++++++++++++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/components/DownloadsComponent.tsx b/components/DownloadsComponent.tsx index a843508..ad7c220 100644 --- a/components/DownloadsComponent.tsx +++ b/components/DownloadsComponent.tsx @@ -67,7 +67,7 @@ const DownloadsComponent: React.FC = () => { const releases = await fetchFilteredReleases(); // This function should return an array of FilteredRelease setOriginalData(releases); setSelectedOptions((prev) => ({...prev, version: prev.version ? prev.version : releases[0].version})) - setVersions(releases.map(release => release.version).filter(version => version >= "v7.6.5")) + setVersions(releases.map(release => release.version)) } catch (e) { setError('Failed to fetch release assets'); console.error(e); diff --git a/components/ReleasesTable.tsx b/components/ReleasesTable.tsx index 3549863..11b7784 100644 --- a/components/ReleasesTable.tsx +++ b/components/ReleasesTable.tsx @@ -26,7 +26,7 @@ const ReleasesTable: React.FC = ({ release , rowNames }) => {asset.architecture} {asset.osDisplayed} - + {asset.name} diff --git a/utils/fetchReleases.tsx b/utils/fetchReleases.tsx index 948b9fc..95d3837 100644 --- a/utils/fetchReleases.tsx +++ b/utils/fetchReleases.tsx @@ -1,4 +1,6 @@ +import semver from 'semver' import { Release, FilteredRelease, packageDisplayedOS, OSEnums, archMapping } from './types'; +import {getAllGithub} from "@/utils/utils"; function getDisplayedOS(filename: string) { for (const rule of packageDisplayedOS) { @@ -24,13 +26,13 @@ function getArchitecture(filename: string) { async function fetchFilteredReleases(): Promise { - const response = await fetch('https://api.github.com/repos/PelicanPlatform/pelican/releases'); - const releases: Release[] = await response.json(); + const releases = await getAllGithub('https://api.github.com/repos/PelicanPlatform/pelican/releases'); // Sort releases by version using semver sort (consider using a library for robust sorting) const sortedReleases = releases.sort((a, b) => b.tag_name.localeCompare(a.tag_name, undefined, {numeric: true, sensitivity: 'base'})); let filteredReleases: FilteredRelease[] = []; + let includedMinorReleases: Set = new Set(); for (const release of sortedReleases) { // Ignore the release if it's a prerelease @@ -38,6 +40,15 @@ async function fetchFilteredReleases(): Promise { continue; } + // Ignore the release if it's a minor release that we've already included + const minorVersion = semver.major(release.tag_name) + semver.minor(release.tag_name); + if (includedMinorReleases.has(minorVersion)) { + continue; + } + + // Add the minor version to the set of included minor releases + includedMinorReleases.add(minorVersion); + filteredReleases.push({ version: release.tag_name, prerelease: release.prerelease, @@ -54,9 +65,10 @@ async function fetchFilteredReleases(): Promise { }; }) }); - } + + return filteredReleases; } diff --git a/utils/utils.ts b/utils/utils.ts index 3e0c800..549bf89 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -11,4 +11,34 @@ export function parseEnum(value: any, enumObj: T): T[keyof T] | undefined { return foundKey } return undefined; -} \ No newline at end of file +} + +/** + * Get all the data from a paginated github api endpoint + * + * @param url + */ +export async function getAllGithub(url: string): Promise { + + let response: Response; + let data: any[]; + + const dataUrl = new URL(url) + dataUrl.searchParams.set('per_page', '100') + + response = await fetch(dataUrl); + data = await response.json(); + + while (response.headers.has('link')) { + const link = response.headers.get("Link"); + const next = link.split(",").find((link: string) => link.includes('rel="next"')); + if (!next) { + break; + } + const nextUrl = next.match(/<(.*)>/)[1]; + response = await fetch(nextUrl); + data = data.concat(await response.json()); + } + + return data; +}