From 87d647d955f51b47ea1c45e18f18c839426d5e6a Mon Sep 17 00:00:00 2001 From: KoolTheba Date: Fri, 28 Apr 2023 16:57:26 +0200 Subject: [PATCH 1/4] feat: added commitHash logic for API request --- src/components/ProjectDetails.tsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/ProjectDetails.tsx b/src/components/ProjectDetails.tsx index 53ad6c3..3203f33 100644 --- a/src/components/ProjectDetails.tsx +++ b/src/components/ProjectDetails.tsx @@ -14,16 +14,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) { From 46cbda991abc7d55ca586e1e248dc69dfad8f3c4 Mon Sep 17 00:00:00 2001 From: KoolTheba Date: Fri, 28 Apr 2023 16:57:45 +0200 Subject: [PATCH 2/4] feat: added route --- src/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index fc7c877..ae4456c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -20,6 +20,10 @@ const router = createHashRouter([ path: "404", element: , }, + { + path: "projects/:platform/:org/:repo/commit/:commitHash", + element: , + }, { path: "projects/:platform/:org/:repo", element: , From fb46e77427ebd86d0b8a22a81f6c4d234ac68f9e Mon Sep 17 00:00:00 2001 From: KoolTheba Date: Fri, 28 Apr 2023 16:57:58 +0200 Subject: [PATCH 3/4] feat: adapted commit message --- src/components/ProjectDetails.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/ProjectDetails.tsx b/src/components/ProjectDetails.tsx index 3203f33..1fb5306 100644 --- a/src/components/ProjectDetails.tsx +++ b/src/components/ProjectDetails.tsx @@ -63,7 +63,7 @@ function ProjectDetails() {

- Last analyzed commit{" "} + Current commit{" "} Date: Fri, 28 Apr 2023 16:58:05 +0200 Subject: [PATCH 4/4] lint: linting --- src/components/ProjectDetails.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/ProjectDetails.tsx b/src/components/ProjectDetails.tsx index 1fb5306..5e057f3 100644 --- a/src/components/ProjectDetails.tsx +++ b/src/components/ProjectDetails.tsx @@ -1,4 +1,3 @@ -import React from "react"; import { useParams } from "react-router-dom"; import { useQuery } from "@tanstack/react-query";