70 lines · 3.0 KB
import { createFileRoute } from "@tanstack/react-router";
import { bypassPushProtection, getPushBlock } from "~/fns/security";
import { useAction } from "~/hooks/use-action";
import { Button } from "~/ui/Button";
import { ErrorBanner } from "~/ui/Callout";
import { Panel } from "~/ui/Panel";
import { RelativeTime } from "~/ui/RelativeTime";
import { TextLink } from "~/ui/TextLink";

export const Route = createFileRoute("/$owner/$repo/security/secret-scanning/unblock/$id")({
  loader: ({ params }) => getPushBlock({ data: { owner: params.owner, repo: params.repo, id: params.id } }),
  component: UnblockPage,
});

const REASONS = [
  { value: "used_in_tests", label: "It's used in tests", hint: "The secret is a fixture and poses no risk." },
  { value: "false_positive", label: "It's a false positive", hint: "The match is not actually a secret." },
  { value: "fix_later", label: "I'll fix it later", hint: "An open alert is kept so the secret gets rotated." },
] as const;

function UnblockPage() {
  const block = Route.useLoaderData();
  const params = Route.useParams();
  const bypass = useAction(bypassPushProtection);
  return (
    <Panel title="Push blocked by push protection">
      <div className="space-y-4 p-4 text-sm">
        <div className="rounded-md border border-kumo-hairline bg-kumo-base/60 p-3">
          <div className="font-medium text-kumo-strong">{block.detectorName}</div>
          <code className="font-mono text-xs text-kumo-subtle">{block.preview}</code>
          <div className="mt-1 text-xs text-kumo-subtle">
            {block.blobSha && <span className="font-mono">blob {block.blobSha.slice(0, 7)} · </span>}
            pushed by {block.pusher ?? "unknown"} <RelativeTime timestamp={block.createdAt} />
          </div>
        </div>
        {block.bypassedAt ? (
          <p className="text-kumo-success">
            Bypassed <RelativeTime timestamp={block.bypassedAt} />. Push again to continue.{" "}
            <TextLink to="/$owner/$repo/security/secret-scanning" params={params}>
              View alerts