Skip to content

Commit

Permalink
feat: copy OSSF Scorecard as image (#4000)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeucapua authored Aug 21, 2024
1 parent 20053e7 commit 690fb38
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
3 changes: 3 additions & 0 deletions components/shared/CopyContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ interface CopyContainerProps {
copySuccessMessage?: string;
copyErrorMessage?: string;
options?: Partial<Options>;
onCopyClick?: () => void;
children: React.ReactNode;
}

export const CopyContainer = ({
copySuccessMessage = "Copied image to clipboard",
copyErrorMessage = "Error copying image",
options,
onCopyClick,
children,
}: CopyContainerProps) => {
const { toast } = useToast();
Expand All @@ -27,6 +29,7 @@ export const CopyContainer = ({
<button
className="absolute top-2 right-2 p-2 bg-white rounded-md shadow-md opacity-0 group-hover:opacity-100 focus-within:opacity-100 scale-95 group-hover:scale-100 transition-all duration-200 ease-in-out transform"
onClick={async () => {
onCopyClick?.();
const node = copyRef.current;

try {
Expand Down
48 changes: 39 additions & 9 deletions pages/s/[org]/[repo]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,45 @@ export default function RepoPage({ repoData, ogImageUrl }: RepoPageProps) {
})
}
/>
<OssfChart
repository={repoData.full_name}
totalScore={repoData.ossf_scorecard_total_score}
dependencyUpdateScore={repoData.ossf_scorecard_dependency_update_score}
maintainedScore={repoData.ossf_scorecard_maintained_score}
fuzzingScore={repoData.ossf_scorecard_fuzzing_score}
isLoading={false}
isError={!repoData.ossf_scorecard_total_score}
/>
{!repoData.ossf_scorecard_total_score ? (
<OssfChart
repository={repoData.full_name}
totalScore={repoData.ossf_scorecard_total_score}
dependencyUpdateScore={repoData.ossf_scorecard_dependency_update_score}
maintainedScore={repoData.ossf_scorecard_maintained_score}
fuzzingScore={repoData.ossf_scorecard_fuzzing_score}
isLoading={false}
isError={!repoData.ossf_scorecard_total_score}
/>
) : (
<CopyContainer
onCopyClick={() => {
posthog.capture("Repo Pages: copied OSSF Scorecard", {
repository: repoData.full_name,
});
}}
options={{
windowWidth: 1700,
allowTaint: true,
onclone: (document, element) => {
element.querySelectorAll("[data-copy-image-branding]").forEach((el) => {
el.classList.remove("hidden");
});
},
}}
>
<CopyImageBranding repository={repoData.full_name} />
<OssfChart
repository={repoData.full_name}
totalScore={repoData.ossf_scorecard_total_score}
dependencyUpdateScore={repoData.ossf_scorecard_dependency_update_score}
maintainedScore={repoData.ossf_scorecard_maintained_score}
fuzzingScore={repoData.ossf_scorecard_fuzzing_score}
isLoading={false}
isError={!repoData.ossf_scorecard_total_score}
/>
</CopyContainer>
)}
</div>

<RossChart
Expand Down

0 comments on commit 690fb38

Please sign in to comment.