Skip to content

Commit

Permalink
Update Install Page components
Browse files Browse the repository at this point in the history
  • Loading branch information
CannonLock committed Dec 2, 2024
1 parent a7e29a3 commit e28afd2
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/DownloadsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion components/ReleasesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ReleasesTable: React.FC<ReleasesTableProps> = ({ release , rowNames }) =>
<TableCell align='center'>{asset.architecture}</TableCell>
<TableCell align='center'>{asset.osDisplayed}</TableCell>
<TableCell align='center'>
<Link href={asset.downloadUrl}>
<Link href={"https://dl.pelicanplatform.org/" + asset.downloadUrl.replace("https://github.com/PelicanPlatform/pelican/releases/download/", "").substring(1)}>
{asset.name}
</Link>
</TableCell>
Expand Down
18 changes: 15 additions & 3 deletions utils/fetchReleases.tsx
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -24,20 +26,29 @@ function getArchitecture(filename: string) {


async function fetchFilteredReleases(): Promise<FilteredRelease[]> {
const response = await fetch('https://api.github.com/repos/PelicanPlatform/pelican/releases');
const releases: Release[] = await response.json();
const releases = await getAllGithub<Release>('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<string> = new Set();

for (const release of sortedReleases) {
// Ignore the release if it's a prerelease
if (release.prerelease) {
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,
Expand All @@ -54,9 +65,10 @@ async function fetchFilteredReleases(): Promise<FilteredRelease[]> {
};
})
});

}



return filteredReleases;
}

Expand Down
32 changes: 31 additions & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,34 @@ export function parseEnum<T>(value: any, enumObj: T): T[keyof T] | undefined {
return foundKey
}
return undefined;
}
}

/**
* Get all the data from a paginated github api endpoint
*
* @param url
*/
export async function getAllGithub<T = any>(url: string): Promise<T[]> {

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;
}

0 comments on commit e28afd2

Please sign in to comment.