Skip to content

Commit

Permalink
feat: added commitHash logic for API request
Browse files Browse the repository at this point in the history
  • Loading branch information
KoolTheba committed Apr 28, 2023
1 parent fca9b81 commit 87d647d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/components/ProjectDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 87d647d

Please sign in to comment.