From 33566425ba45ebea4bdda174e09fe9acf286b72b Mon Sep 17 00:00:00 2001 From: Jeffrey Yasskin Date: Thu, 26 Oct 2023 21:43:00 -0700 Subject: [PATCH] Add a JSON summary for each repo. --- frontend/src/pages/[org]/[repo].json.ts | 34 +++++++++++++++++++++++++ frontend/src/pages/slo.json.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 frontend/src/pages/[org]/[repo].json.ts 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) );