diff --git a/frontend/src/pages/[org]/[repo].json.ts b/frontend/src/pages/[org]/[repo].json.ts new file mode 100644 index 0000000..c9ed250 --- /dev/null +++ b/frontend/src/pages/[org]/[repo].json.ts @@ -0,0 +1,34 @@ +import { RepoSummary } from "@lib/repo-summaries"; +import { groupBySlo } from "@lib/slo"; +import type { + APIRoute, + GetStaticPaths, + InferGetStaticPropsType +} from "astro"; + +export const getStaticPaths = (async () => { + const repos = RepoSummary.array().parse( + Object.values(await import.meta.glob("../../../../scanner/summaries/*/*.json", { eager: true })) + ); + return repos.map((repo) => ({ + params: { org: repo.org, repo: repo.repo }, + props: { details: repo }, + })); +}) satisfies GetStaticPaths; + +type Props = InferGetStaticPropsType; + +export const GET: APIRoute = ({ props }) => { + const { details } = props as Props; + const groups = groupBySlo(details.issues); + return new Response( + JSON.stringify({ + triageViolations: groups.triageViolations.length, + urgentViolations: groups.urgentViolations.length, + importantViolations: groups.importantViolations.length, + needTriage: groups.untriaged.length, + urgent: groups.urgent.length, + important: groups.important.length, + other: groups.other.length, + })); +} diff --git a/frontend/src/pages/slo.json.ts b/frontend/src/pages/slo.json.ts index d2cb430..d891b8f 100644 --- a/frontend/src/pages/slo.json.ts +++ b/frontend/src/pages/slo.json.ts @@ -2,7 +2,7 @@ import { RepoSummary } from '@lib/repo-summaries'; import { groupBySlo } from '@lib/slo'; import type { APIRoute } from 'astro'; -export const GET: APIRoute = async ({ params, request }) => { +export const GET: APIRoute = async () => { const repos = Object.values(await import.meta.glob("../../../scanner/summaries/*/*.json", { eager: true })).map( (repo) => RepoSummary.parse(repo) );