136 lines
6.3 KiB
TypeScript
136 lines
6.3 KiB
TypeScript
// 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, 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 { 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 — Peppa FACTORY") };
|
|
}
|
|
|
|
type Params = { q?: string; show?: string };
|
|
|
|
function RepoRow({ r, t }: { r: GiteaServerRepo; t: Translator }) {
|
|
return (
|
|
<li className="flex flex-col gap-1 border-b border-border px-4 py-3 last:border-b-0">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<a href={r.htmlUrl} target="_blank" rel="noreferrer" className="font-mono text-sm font-medium">
|
|
{r.fullName}
|
|
<ExternalLink className="ml-1 inline size-3" />
|
|
</a>
|
|
{r.private ? (
|
|
<Badge variant="secondary">
|
|
<Lock className="size-3" />
|
|
{t("приватный")}
|
|
</Badge>
|
|
) : (
|
|
<Badge variant="info">{t("публичный")}</Badge>
|
|
)}
|
|
{r.empty && <Badge variant="warn">{t("пустой")}</Badge>}
|
|
{r.archived && <Badge variant="secondary">{t("в архиве")}</Badge>}
|
|
{r.fork && <Badge variant="secondary">{t("форк")}</Badge>}
|
|
{r.project ? (
|
|
<Link href={`/p/${r.project.key}`} className="ml-auto text-xs">
|
|
{t("проект {key} · {name}", { key: r.project.key, name: r.project.name })}
|
|
</Link>
|
|
) : (
|
|
<span className="ml-auto text-xs text-muted-foreground">{t("не подключён к проекту")}</span>
|
|
)}
|
|
</div>
|
|
{r.description && <div className="text-sm text-muted-foreground">{r.description}</div>}
|
|
<div className="text-xs text-muted-foreground">
|
|
{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` })}
|
|
</div>
|
|
</li>
|
|
);
|
|
}
|
|
|
|
export default async function GiteaPage({ searchParams }: { searchParams: Promise<Params> }) {
|
|
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 = q.show === "linked" || q.show === "unlinked" ? q.show : "all";
|
|
const repos = o.repos.filter(
|
|
(r) => (!needle || r.fullName.toLowerCase().includes(needle) || r.description.toLowerCase().includes(needle)) && (show === "all" || (show === "linked") === !!r.project),
|
|
);
|
|
const owners = new Map<string, number>();
|
|
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 (
|
|
<Workspace>
|
|
<div className="max-w-4xl">
|
|
<PageHeader title={<><GitBranch className="mr-1 inline size-5 text-primary" />Gitea</>}>
|
|
{t("Git-сервер платформы и репозитории на нём — как их видит бот Peppa FACTORY. Раздел видят только суперадмины.")}
|
|
</PageHeader>
|
|
|
|
<Section title={t("Сервер")}>
|
|
<Card className="flex flex-col gap-1 p-4 text-sm">
|
|
<div>
|
|
{t("Адрес")}:{" "}
|
|
{o.url ? (
|
|
<a href={o.url} target="_blank" rel="noreferrer" className="font-mono">
|
|
{o.url}
|
|
</a>
|
|
) : (
|
|
"—"
|
|
)}
|
|
</div>
|
|
<div>
|
|
{t("Бот")}: <span className="font-mono">{o.bot?.login ?? "—"}</span>
|
|
{o.bot && (o.bot.admin ? <Badge variant="ok" className="ml-2">{t("админ сервера — видит все репозитории")}</Badge> : <Badge variant="warn" className="ml-2">{t("не админ — видит публичные и свои репозитории")}</Badge>)}
|
|
</div>
|
|
{o.repos.length > 0 && (
|
|
<div className="text-muted-foreground">
|
|
{t("Репозиториев: {n} · подключены к проектам: {linked}", { n: o.repos.length, linked })} ·{" "}
|
|
{[...owners].sort((a, b) => b[1] - a[1]).map(([owner, n]) => `${owner} ${n}`).join(", ")}
|
|
</div>
|
|
)}
|
|
</Card>
|
|
</Section>
|
|
|
|
{o.error && <Notice>{t("Gitea не ответила: {error}", { error: o.error })}</Notice>}
|
|
|
|
<Section title={t("Репозитории")} count={repos.length}>
|
|
<form className="mb-3 flex flex-wrap items-center gap-2" action="/gitea">
|
|
<Input name="q" defaultValue={q.q ?? ""} placeholder={t("Поиск по имени или описанию")} className="h-8 max-w-xs" />
|
|
<select name="show" defaultValue={show} className="h-8 rounded-md border border-input bg-background px-2 text-sm">
|
|
<option value="all">{t("все")}</option>
|
|
<option value="linked">{t("подключённые к проектам")}</option>
|
|
<option value="unlinked">{t("без проекта")}</option>
|
|
</select>
|
|
<Button type="submit" size="sm">
|
|
{t("Показать")}
|
|
</Button>
|
|
</form>
|
|
{repos.length === 0 ? (
|
|
<Empty>{t("Репозиториев не найдено.")}</Empty>
|
|
) : (
|
|
<Card className="p-0">
|
|
<ul>
|
|
{repos.map((r) => (
|
|
<RepoRow key={r.fullName} r={r} t={t} />
|
|
))}
|
|
</ul>
|
|
</Card>
|
|
)}
|
|
</Section>
|
|
</div>
|
|
</Workspace>
|
|
);
|
|
}
|