// glossary-ignore-file: superadmin-only page about the platform's git server — «репозиторий» is the literal object here
import Link from "next/link";
import { notFound } from "next/navigation";
import { ExternalLink, GitBranch, Lock } from "lucide-react";
import { giteaServerOverview, isSuperadmin, type GiteaServerRepo } from "@peppa/core";
import { ago, Empty, Flash, Notice, PageHeader, Section } from "@/components/common";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Workspace } from "@/components/Workspace";
import { requireUser } from "@/lib/auth";
import { makeRepoPrivateAction } from "./actions";
import { db } from "@/lib/db";
import { getT } from "@/lib/i18n";
import type { Translator } from "@peppa/shared/i18n";
export async function generateMetadata() {
const t = await getT();
return { title: t("Gitea — FORGE") };
}
type Params = { q?: string; show?: string; closed?: string; error?: string };
type Show = "all" | "linked" | "unlinked" | "public";
function RepoRow({ r, t, q, show }: { r: GiteaServerRepo; t: Translator; q: string; show: Show }) {
return (
{r.fullName}
{r.private ? (
{t("приватный")}
) : (
{t("публичный")}
)}
{r.empty &&
{t("пустой")} }
{r.archived &&
{t("в архиве")} }
{r.fork &&
{t("форк")} }
{r.project ? (
{t("проект {key} · {name}", { key: r.project.key, name: r.project.name })}
) : (
{t("не подключён к проекту")}
)}
{r.description && {r.description}
}
{!r.private && (
// PEP-280: one repository at a time; opening it again is the owner's decision in the project settings.
)}
{t("ветка {branch} · обновлён {when} · {size}", { branch: r.defaultBranch || "—", when: ago(r.updatedAt, t), size: r.sizeKb >= 1024 ? `${(r.sizeKb / 1024).toFixed(1)} MB` : `${r.sizeKb} KB` })}
);
}
export default async function GiteaPage({ searchParams }: { searchParams: Promise }) {
const user = await requireUser();
const t = await getT();
if (!(await isSuperadmin(db, user))) notFound();
const q = await searchParams;
const o = await giteaServerOverview(db);
const needle = (q.q ?? "").trim().toLowerCase();
const show: Show = q.show === "linked" || q.show === "unlinked" || q.show === "public" ? q.show : "all";
const repos = o.repos.filter(
(r) =>
(!needle || r.fullName.toLowerCase().includes(needle) || r.description.toLowerCase().includes(needle)) &&
(show === "all" || (show === "public" ? !r.private : (show === "linked") === !!r.project)),
);
const open = o.repos.filter((r) => !r.private).length;
const owners = new Map();
for (const r of o.repos) owners.set(r.owner, (owners.get(r.owner) ?? 0) + 1);
const linked = o.repos.filter((r) => r.project).length;
return (
Gitea>}>
{t("Git-сервер платформы и репозитории на нём — как их видит бот FORGE. Раздел видят только суперадмины.")}
{t("Адрес")}:{" "}
{o.url ? (
{o.url}
) : (
"—"
)}
{t("Бот")}: {o.bot?.login ?? "—"}
{o.bot && (o.bot.admin ? {t("админ сервера — видит все репозитории")} : {t("не админ — видит публичные и свои репозитории")} )}
{o.repos.length > 0 && (
{t("Репозиториев: {n} · подключены к проектам: {linked}", { n: o.repos.length, linked })} ·{" "}
{[...owners].sort((a, b) => b[1] - a[1]).map(([owner, n]) => `${owner} ${n}`).join(", ")}
)}
{o.repos.length > 0 && (
{open > 0 ? (
{t("Публичных: {n} — их видит любой, у кого есть доступ к Gitea", { n: open })}
) : (
{t("Публичных нет")}
)}
)}
{q.closed &&
{t("{repo} теперь закрытый: его видят только владелец, участники и бот", { repo: q.closed })} }
{o.error &&
{t("Gitea не ответила: {error}", { error: o.error })} }
{repos.length === 0 ? (
{t("Репозиториев не найдено.")}
) : (
)}
);
}