import { notFound } from "next/navigation"; import { ExternalLink, Plus, Rocket } from "lucide-react"; import { columnOf, currentReleases, describeRepo, isPlatform, listReleases, bugsinkWebhookBase, openPulls, platformReleaseCandidate, platformReleaseOffers, repoOverview, type Release } from "@peppa/runner"; import { taskProgress, getAutonomy, getIncidentSettings, getReviewSettings, isSuperadmin, listEpics, listErrorSources, listIncidents, listMembers, listPools, listSpecs, projectPool, repoAudience, repoVisibilityLabel } from "@peppa/core"; import { LiveRefresh } from "@/components/LiveRefresh"; import { PanelSection } from "@/components/ActivityAside"; import { Board, type Card } from "@/components/Board"; import { Hidden, SessionCard } from "@/components/cards"; import { Empty, Flash, Key, Notice, PageHeader, Section } from "@/components/common"; import { IncidentSettingsPanel, IncidentsSection } from "@/components/Incidents"; import { AutonomyPanel } from "@/components/Autonomy"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input, NativeSelect, Textarea } from "@/components/ui/input"; import { SettingsDialog } from "@/components/SettingsDialog"; import { Workspace } from "@/components/Workspace"; import { requireUser } from "@/lib/auth"; import { cn } from "@/lib/utils"; import { db } from "@/lib/db"; import { board, projectForUserByKey, projectSessions } from "@/lib/queries"; import { addProjectMember, addTask, deployProdAction, grantRepoAccessToMembers, removeProjectMember, saveReviewSettingsAction, setProjectVisibilityAction } from "../../actions"; import { CodeTab, EpicsPanel, PullsTab, SpecsTab } from "./tabs"; import { setProjectPoolAction } from "../../subscriptions/actions"; const RELEASE_STATUS: Record = { deploying: { label: "выкатывается", tone: "info" }, healthy: { label: "работает", tone: "ok" }, rolled_back: { label: "откат", tone: "warn" }, failed: { label: "не поднялся", tone: "danger" }, removed: { label: "удалён", tone: "muted" }, }; const TABS = [ { id: "board", label: "Доска" }, { id: "code", label: "Код" }, { id: "specs", label: "Спеки" }, { id: "pulls", label: "PR" }, { id: "releases", label: "Релизы" }, { id: "bugs", label: "Баги" }, { id: "sessions", label: "Сессии" }, ] as const; function EnvLine({ name, r }: { name: string; r: Release | null | undefined }) { return (
{name} {r ? ( {r.sha.slice(0, 7)} {r.host && ( {r.host} )} ) : ( нет )}
); } export default async function ProjectPage({ params, searchParams }: { params: Promise<{ key: string }>; searchParams: Promise<{ error?: string; created?: string; tab?: string; epic?: string }> }) { const user = await requireUser(); const { key } = await params; const { error, created, tab: tabParam, epic: epicParam } = await searchParams; const tab = TABS.find((t) => t.id === tabParam)?.id ?? "board"; const p = await projectForUserByKey(user.id, key).catch(() => null); if (!p) notFound(); const [{ tasks }, epics, sessions, team, repo, incidentSettings, sources, incidents, releases, current, reviewer] = await Promise.all([ board(p.id), listEpics(db, p.id), projectSessions(p.id), listMembers(db, p), describeRepo(db, p), getIncidentSettings(db, p.id), listErrorSources(db, p.id), listIncidents(db, p.id), listReleases(db, p.id, 15), currentReleases(db, p.id), getReviewSettings(db, p.id), ]); // Peppa itself has no staging: its prod candidate is the newest green main (PEP-18). const prodCandidate = isPlatform(p) ? ((await platformReleaseOffers(db)) ? await platformReleaseCandidate(db, p) : null) : (current.staging?.sha ?? null); const collaborators = new Set((repo.collaborators ?? []).map((l) => l.toLowerCase())); // Members who are not repo collaborators (only known when Gitea listed them; owners of the namespace see it anyway). const noRepoAccess = (login: string) => repo.collaborators !== null && login.toLowerCase() !== p.giteaOwner.toLowerCase() && !collaborators.has(login.toLowerCase()); const missingAccess = team.members.some((m) => noRepoAccess(m.login)); const isOwner = p.ownerId === user.id; // PEP-67: default subscription pool; only a superadmin changes it. const superadmin = await isSuperadmin(db, user); const [pool, pools, autonomy] = await Promise.all([projectPool(db, p.id), superadmin ? listPools(db) : Promise.resolve([]), getAutonomy(db, p.id)]); // Epic filter (PEP-66): only an open epic of this project filters; anything else shows all. const epicFilter = epics.find((e) => String(e.id) === epicParam) ?? null; const boardHref = (epicId?: number) => (epicId ? `/p/${p.key}?epic=${epicId}` : `/p/${p.key}`); const back = tab === "board" ? boardHref(epicFilter?.id) : `/p/${p.key}?tab=${tab}`; const epicTitle = new Map(epics.map((e) => [e.id, e.title])); const cards: Card[] = tasks .filter((t) => !epicFilter || t.goalId === epicFilter.id) .map((t) => { const pr = columnOf(t.status) === "in_progress" ? taskProgress(p, t.openspecChange) : null; return { key: `${p.key}-${t.number}`, title: t.title, status: t.status, column: columnOf(t.status), epic: t.goalId ? (epicTitle.get(t.goalId) ?? null) : null, // PEP-33: tasks.md progress of stories in work. progress: pr && { done: pr.done, total: pr.total, current: pr.current }, }; }); // Gitea and the working copy are read only for the open tab. const [code, pulls] = await Promise.all([tab === "code" ? repoOverview(db, p) : null, tab === "pulls" ? openPulls(db, p) : null]); const specs = tab === "specs" ? listSpecs(p) : []; const aside = (
Где
{repo.fullName}
Пространство
{p.giteaOwner} {repo.ownerKind && ` — ${repo.ownerKind === "org" ? "организация" : "личное"}`}
Видимость
{repoVisibilityLabel(repo.private)}
Кто видит
{repoAudience(repo)}
Рабочая копия
{p.workspacePath}
{isOwner && repo.private !== null && (
)}
{isOwner && repo.private !== null && (

{repo.private ? "Публичный репозиторий видят все, у кого есть доступ к Gitea." : "Приватный репозиторий видят только владелец пространства, соавторы и peppa-bot."} Видимость меняется в Gitea сразу.

)}