Files
fristydev/lib/gitea.ts
T

68 lines
1.8 KiB
TypeScript

import { warnDev } from "@/lib/log";
const GITEA_API = "https://git.fristy.net/api/v1";
const GITEA_USER = "fristy";
const EXCLUDED_REPOS = new Set([".profile"]);
const MAX_REPOS = 8;
export interface GiteaRepo {
id: number;
name: string;
fullName: string;
description: string | null;
language: string | null;
htmlUrl: string;
website: string | null;
stars: number;
forks: number;
updatedAt: string;
}
interface GiteaApiRepo {
id: number;
name: string;
full_name: string;
description: string | null;
language: string | null;
html_url: string;
website: string;
stars_count: number;
forks_count: number;
updated_at: string;
}
export async function getRepos(): Promise<GiteaRepo[]> {
try {
const response = await fetch(
`${GITEA_API}/users/${GITEA_USER}/repos?limit=50&sort=updated&order=desc`,
{ next: { revalidate: 3600 } },
);
if (!response.ok) {
warnDev(`cannot fetch gitea repos: ${response.status}`);
return [];
}
const data = (await response.json()) as GiteaApiRepo[];
return data
.filter((repo) => !EXCLUDED_REPOS.has(repo.name))
.map((repo) => ({
id: repo.id,
name: repo.name,
fullName: repo.full_name,
description: repo.description,
language: repo.language,
htmlUrl: repo.html_url,
website: repo.website || null,
stars: repo.stars_count,
forks: repo.forks_count,
updatedAt: repo.updated_at,
}))
.sort((a, b) => +new Date(b.updatedAt) - +new Date(a.updatedAt))
.slice(0, MAX_REPOS);
} catch {
warnDev("cannot fetch gitea repos");
return [];
}
}