Skip to content

Commit

Permalink
Add a JSON summary for each repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
jyasskin committed Oct 27, 2023
1 parent eda9ca9 commit 3356642
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions frontend/src/pages/[org]/[repo].json.ts
Original file line number Diff line number Diff line change
@@ -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<typeof getStaticPaths>;

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,
}));
}
2 changes: 1 addition & 1 deletion frontend/src/pages/slo.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down

0 comments on commit 3356642

Please sign in to comment.