237 lines · 9.1 KB
import { z } from "zod";
import { first } from "../db";
import { repoDb } from "../scoped-db";
import { notFoundError } from "../errors";
import { limitWrite } from "../limits";
import { setAutoMerge, setMergeQueue, updatePull } from "../pull-automation";
import { loadPull } from "../pulls";
import {
  deleteReviewComment,
  dismissReview,
  editReviewComment,
  replyReviewComment,
  requestReviewers,
  rerequestPullReview,
  resolveReviewThread,
  reviewCommentInput,
  submitReview,
} from "../reviews-write";
import { markdownBody } from "~/lib/validation";
import { noContent, pullJson, readJson, requireScopedPull, unprocessable } from "./http";
import type { ApiContext } from "./http";

const sha = z.string().regex(/^[0-9a-f]{40}$/, "Must be a 40-character commit SHA");
const side = z.enum(["LEFT", "RIGHT"]);

const reviewInput = z.object({
  event: z
    .string()
    .transform((value) => value.toLowerCase())
    .pipe(z.enum(["approve", "request_changes", "comment"])),
  body: markdownBody.default(""),
  commit_id: sha,
  comments: z
    .array(
      z.object({
        path: z.string().min(1),
        line: z.number().int().positive(),
        side: side.default("RIGHT"),
        start_line: z.number().int().positive().nullish(),
        start_side: side.nullish(),