Skip to content

Commit

Permalink
Merge pull request #36 from KoolTheba/feat/immutable-reports
Browse files Browse the repository at this point in the history
Feat: immutable reports
  • Loading branch information
KoolTheba authored Apr 28, 2023
2 parents fca9b81 + a801b05 commit ecfd447
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/components/ProjectDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from "react";
import { useParams } from "react-router-dom";
import { useQuery } from "@tanstack/react-query";

Expand All @@ -14,16 +13,29 @@ interface ScoreElement {
};
}

interface paramsTypes {
platform: string | undefined;
org: string | undefined;
repo: string | undefined;
commitHash: string | undefined;
}

function ProjectDetails() {
const params = useParams();
const { platform, org, repo } = params;
const { platform, org, repo, commitHash } = params;

const getScorecardUrl = (params: paramsTypes) :string => {
let baseUrl = `https://api.securityscorecards.dev/projects/${params.platform}/${params.org}/${params.repo}`
if(params.commitHash){
baseUrl += `/?commit=${params.commitHash}`
}
return baseUrl
}

const { isLoading, error, data } = useQuery({
queryKey: ["projectData"],
queryFn: () =>
fetch(
`https://api.securityscorecards.dev/projects/${platform}/${org}/${repo}`
).then((res) => res.json()),
fetch(getScorecardUrl({platform, org, repo, commitHash})).then((res) => res.json()),
});

if (isLoading) {
Expand All @@ -50,7 +62,7 @@ function ProjectDetails() {
</a>
</p>
<p>
Last analyzed commit{" "}
Current commit{" "}
<a
href={`https://github.com/${org}/${repo}/commit/${data.repo.commit}`}
target="_blank"
Expand Down
4 changes: 4 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const router = createHashRouter([
path: "404",
element: <Error404 />,
},
{
path: "projects/:platform/:org/:repo/commit/:commitHash",
element: <ProjectDetails />,
},
{
path: "projects/:platform/:org/:repo",
element: <ProjectDetails />,
Expand Down

0 comments on commit ecfd447

Please sign in to comment.