369 lines · 14.1 KB
import { env } from "cloudflare:workers";
import { all, first, run, batch, stmt } from "./db";
import { randomId } from "./crypto";
import { loadRepoById } from "./repos";
import { loadProtections, protectionFor, bypassesProtection } from "./protection";
import { listCommitStatuses } from "./statuses";
import { authenticatedRemote, mintRepoToken } from "./git/artifacts";
import { ZERO_SHA, withStore } from "./git/store";
import { isAncestor } from "./git/history";
import { triggerPush } from "./events/push-trigger";
import { inWorkerMergeability, landInWorker, loadPullRepos } from "./pull-merge";
import { afterMerged, codeOwnerReviewsMissing, kickMergeAutomation } from "./merge-automation";
import type { MergeMethod, Permission, RepoRow } from "~/lib/types";

const MERGE_TOKEN_TTL_SECONDS = 1800;
const MAX_EXTERNAL_MERGE_CHECKS = 10;
const EXIT_CONFLICT = 2;
const EXIT_HEAD_MOVED = 3;
const EXIT_BASE_MOVED = 6;

export type PullRow = {
  issue_id: string;
  repo_id: string;
  number: number;
  title: string;
  body: string;
  state: "open" | "closed";
  author_id: string;
  head_repo_id: string;
  head_ref: string;
  head_sha: string;
  base_ref: string;
  base_sha: string;
  merge_base_sha: string | null;
  draft: number;
  mergeable: "unknown" | "clean" | "conflict";
  merged_at: number | null;
  merged_by: string | null;
  merge_commit_sha: string | null;
  merge_method: string | null;