.ts
TypeScript
(application/typescript)
// 1st-party
import type { ServiceApiContract } from "@ethicdevs/react-monolith";
// 3rd-party
import type { FastifyRequest } from "fastify";
// generated via script[generate via prisma]
import { Prisma, PullRequest, Repository, User } from "@prisma/client";

export interface CreatePullRequestDTO {
  author: User;
  summary: string;
  textMd: string;
  source: {
    repository: Repository;
    fromBranch: string;
  };
  target: {
    repository: Repository;
    destBranch: string;
  };
}

export type PullRequestSelectOrIncludes =
  | { select?: Prisma.PullRequestSelect }
  | { includes?: Prisma.PullRequestInclude };

export interface MergePullRequestDTO {
  pullRequestId: string;
  mergeMessage?: string;
  // delete the source branch in the source repository after merge if requested
  deleteSourceBranch?: boolean;
  // could extend with mergeStrategy in future (e.g., merge, squash, rebase)
}

export interface MergePullRequestResult {
  success: boolean;
  updatedPullRequest?: PullRequest;
}

export interface PullRequestServiceAPI extends ServiceApiContract {
  getPullRequestById(
    pullRequestId: string,
    selectOrIncludes?: PullRequestSelectOrIncludes,
  ): Promise<PullRequest | null>;
  getPullRequestByUid<R = PullRequest | null>(
    orgSlug: string,
    repoSlug: string,
    pullRequestUid: number,
    selectOrIncludes?: PullRequestSelectOrIncludes,
  ): Promise<R>;
  getPullRequestsInRepository(
    repository: Repository,
    selectOrIncludes?: PullRequestSelectOrIncludes,
  ): Promise<PullRequest[]>;
  createPullRequest(dto: CreatePullRequestDTO): Promise<PullRequest>;
  mergePullRequest(dto: MergePullRequestDTO): Promise<MergePullRequestResult>;
}

export interface PullRequestServiceDeps {
  request: FastifyRequest;
}