GitFOSS
.ts
TypeScript
(application/typescript)
// std
import { PathLike } from "node:fs";
// 1st-party
import type { ServiceApiContract } from "@ethicdevs/react-monolith";
// 3rd-party
import type { FastifyRequest } from "fastify";
// generated via script[generate:prisma]
import type { Organization, Repository, User } from "@prisma/client";
// app
import type {
  RepositoryFile,
  RepositoryFileContent,
  RepositoryFileDiff,
  RepositoryHead,
  RepositoryLog,
  RepositoryObject,
  RepositoryWithForkedFromRepo,
  RepositoryWithParentAndForkedFromRepos,
} from "../../types";

export interface CreateRepositoryDTO {
  parentOrgSlug: string;
  repoSlug: string;
  repoData: Omit<
    Repository,
    "id" | "slug" | "createdAt" | "updatedAt" | "organizationId"
  >;
  repoInitFlags: {
    orgRepositoriesDir: PathLike;
    withBaseReadmeFile: boolean;
    withLicense: boolean;
    withLicenseKind: string;
  };
}

export interface ForkRepositoryDTO {
  source: {
    parentOrg: Organization;
    parentOrgRepositoriesDir: PathLike;
    repository: Repository;
  };
  target: {
    parentOrg: Organization;
    parentOrgRepositoriesDir: PathLike;
    repoSlug: string;
    repoData: Pick<Repository, "displayName" | "visibility">;
  };
}

export interface RepositoryServiceAPI extends ServiceApiContract {
  canUserAccessRepository(
    user: User | null,
    repo: Repository
  ): Promise<boolean>;
  createRepository(dto: CreateRepositoryDTO): Promise<Repository>;
  forkRepository(dto: ForkRepositoryDTO): Promise<Repository>;
  getCurrentUserRepositoryForks(
    repository: Repository
  ): Promise<RepositoryWithParentAndForkedFromRepos[]>;
  getRepository(
    orgSlug: string,
    repoSlug: string
  ): Promise<RepositoryWithForkedFromRepo | null>;
  getRepositoryBranches(
    repository: Repository,
    onlyLocalBranches?: boolean
  ): Promise<string[]>;
  getRepositoryById(
    repoId: string
  ): Promise<RepositoryWithForkedFromRepo | null>;
  getRepositoryCommitLog(
    repository: Repository,
    path?: string,
    ref?: string,
    onlyLast?: boolean
  ): Promise<RepositoryLog[]>;
  getRepositoryExploreCollection(): Promise<
    (Repository & { parentOrg: Organization })[]
  >;
  getRepositoryFileContent(
    repository: Repository,
    path: string,
    ref?: string
  ): Promise<null | RepositoryFileContent>;
  getRepositoryFileContentBase64(
    repository: Repository,
    path: string,
    ref?: string
  ): Promise<null | RepositoryFileContent>;
  getRepositoryFiles(
    repository: Repository,
    path?: string,
    ref?: string
  ): Promise<RepositoryFile[]>;
  getRepositoryHead(
    repository: Repository,
    ref?: string
  ): Promise<RepositoryHead>;
  getRepositoryHTTPCloneUrl(repository: Repository): Promise<string>;
  getRepositorySSHCloneUrl(repository: Repository): Promise<string>;
  getRepositoryObject(
    repository: Repository,
    objectId: String
  ): Promise<RepositoryObject | null>;
  getRepositoryRefDiff(
    repository: Repository,
    refA: string,
    refB?: string
  ): Promise<RepositoryFileDiff[]>;
  getRepositoryRemoteRefDiff(
    sourceRepo: Repository,
    sourceFromBranch: string,
    targetRepo: Repository,
    targetDestBranch: string
  ): Promise<RepositoryFileDiff[]>;
  getRepositoryTags(repository: Repository): Promise<string[]>;
  isFileInRepositoryPath(
    repository: Repository,
    path: string,
    filesToMatch: string[],
    ref?: string
  ): Promise<string[]>;
}

export interface RepositoryServiceDeps {
  request: FastifyRequest;
}