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: copy OSSF Scorecard as image #4000

Merged
merged 1 commit into from
Aug 21, 2024
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
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
Loading