477 lines · 18.7 KB
import { WorkflowEntrypoint } from "cloudflare:workers";
import { kickRepoInsights } from "../insights/repo-insights-do";
import type { WorkflowEvent, WorkflowStep } from "cloudflare:workers";
import { z } from "zod";
import { run } from "../db";
import { repoDb } from "../scoped-db";
import { isBackfilling, loadRepoById, loadRepoByArtifactsName } from "../repos";
import { loadUserById } from "../auth";
import { refreshRefs } from "../git/refs";
import { ZERO_SHA, withStore } from "../git/store";
import { compareCommits } from "../git/history";
import { diffTreesBounded } from "../git/diff";
import { checkMergeability, locatePullByIssueId, syncPullsForPush } from "../pulls";
import { scheduleWorkflows } from "../ci/scheduler";
import { indexRepoWorkflows } from "../ci/workflow-index";
import { forkPushNeedsApproval } from "./fork-approval";
import { emitWebhook, publicUrl, recordActivity } from "./emit";
import { pushEventId } from "./push-trigger";
import type { PushParams } from "./push-trigger";
import { closeIssuesFromCommits } from "../issues";
import { requestCodeIndex } from "../code/search-index";
import { warmLastCommits } from "../code/path-history";
import { isHiddenRef } from "../git/hidden-refs";
import { deploySitesForPush } from "../sites/triggers";
import { queuePushSecurity } from "../security/queue";
import type { CommitSummary } from "~/lib/types";
import { notifyMirrorOfPush } from "../mirror/notify";

const MAX_PUSH_COMMITS = 50;
const MAX_CHANGED_PATHS = 3000;
const MAX_MERGEABILITY_CHECKS = 10;
const MAX_PULL_CI_TRIGGERS = 20;

const internalPush = z.object({
  source: z.enum(["proxy", "internal", "artifacts"]),
  repoId: z.string().nullable(),
  artifactsName: z.string().nullable(),
  ref: z.string(),
  before: z.string(),
  after: z.string(),