peppa/packages/core/src/repo-info.ts
2026-11-16 09:52:35 +05:00

30 lines
1.6 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.

// glossary-ignore-file: где лежит код и кто его видит, показано только в виде «Инженер»
// Where a project's Gitea repo is and who can see it (PEP-15). Read live from Gitea:
// visibility and collaborators can be changed there, so Peppa does not store them.
import { m as tr } from "@peppa/shared/i18n";
export interface RepoInfo {
/** owner/repo */
fullName: string;
url: string;
/** Null when Gitea could not be asked. */
private: boolean | null;
ownerKind: "user" | "org" | null;
collaborators: string[] | null;
}
/** Who can see the repo, in one Russian sentence fragment. */
export function repoAudience(r: Pick<RepoInfo, "fullName" | "private" | "ownerKind" | "collaborators">): string {
if (r.private === null) return tr("не удалось узнать у Gitea");
if (!r.private) return tr("все, у кого есть доступ к Gitea");
const owner = r.fullName.split("/")[0]!;
const list = r.collaborators?.length ? r.collaborators.join(", ") : null;
if (r.ownerKind === "org") {
return list ? tr("участники организации {owner} с доступом к репозиторию и соавторы: {list}", { owner, list }) : tr("участники организации {owner} с доступом к репозиторию", { owner });
}
return list ? tr("{owner} и соавторы: {list}", { owner, list }) : owner;
}
export function repoVisibilityLabel(isPrivate: boolean | null): string {
return isPrivate === null ? tr("видимость неизвестна") : isPrivate ? tr("приватный") : tr("публичный");
}