Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: immutable reports #36

Merged
merged 4 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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