import { env, waitUntil } from "cloudflare:workers";
import { dropPullRefsForIssue } from "./git/pull-bridge";
import { all, first, run, batch, stmt } from "./db";
import { randomId } from "./crypto";
import { hasPermission, loadRepoById, repoPermission } from "./repos";
import { loadProtections, protectionFor, bypassesProtection } from "./protection";
import { listCommitStatuses, requiredCheckResults } 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 type { Landed } from "./pull-merge";
import { RebaseConflictError, rebaseInWorker } from "./pull-rebase";
import { actorViewer, afterMerged, codeOwnerBlockers, 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;