Files
legal-ai/web-ui/src/components/cases/create-repo-button.tsx
Chaim fa70944ed4
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 1m29s
case-create: surface Gitea repo result + UI retry button
The auto-creation in case_create had two failure modes that combined to
make repos silently missing: a stale GITEA_TOKEN returning 401, and the
outer try/except in case_create that swallowed every exception with a
bare pass. Result: cases like 8174-24 ended up with a local git repo and
Paperclip project but no Gitea repo, with no signal anywhere.

_setup_gitea_remote now returns {ok, url, error} and never raises; the
result is attached to the case JSON and the FastAPI endpoint logs a
warning when ok=false. The UI gets a "צור ריפו ב-Gitea" button on the
case header that appears only when the repo or remote is missing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 18:12:05 +00:00

60 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { toast } from "sonner";
import { Cloud, Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
useCreateGiteaRepo,
useGitStatus,
type CaseDetail,
} from "@/lib/api/cases";
export function CreateRepoButton({ data }: { data?: CaseDetail }) {
const { data: gitStatus } = useGitStatus(data?.case_number);
const createRepo = useCreateGiteaRepo(data?.case_number);
if (!data?.case_number || !gitStatus) return null;
/* Show only when something is actually missing — repo, remote, or
* unpushed commits. If everything is in sync, the SyncIndicator already
* communicates that. */
const needsRepo = gitStatus.error === "no_repo" || !gitStatus.has_remote;
if (!needsRepo) return null;
function handleClick() {
if (!data) return;
createRepo.mutate(
{ title: data.title ?? "", description: data.subject ?? "" },
{
onSuccess: (res) =>
toast.success(
res.pushed
? `הריפו נוצר ב-Gitea: ${res.repo_url}`
: `הריפו נוצר אך ה-push נכשל. בדוק את הלוגים של ה-backend.`,
),
onError: (err) =>
toast.error(
err instanceof Error ? err.message : "יצירת הריפו נכשלה",
),
},
);
}
return (
<Button
variant="outline"
size="sm"
onClick={handleClick}
disabled={createRepo.isPending}
title="יצירת ריפו ב-Gitea וקישור התיק המקומי אליו"
>
{createRepo.isPending ? (
<Loader2 className="me-1 h-3.5 w-3.5 animate-spin" />
) : (
<Cloud className="me-1 h-3.5 w-3.5" />
)}
צור ריפו ב-Gitea
</Button>
);
}