501 lines · 21.5 KB
import { jobTokenAccess, jobTokenRepoPermission, markJobTokenPush } from "../ci/job-token";
import { writeRefusal } from "~/lib/email-verification";
import { enforceRateLimit, requestIp } from "../limits";
import { HttpError } from "../errors";
import { hasPermission, loadRepo, repoReadOnlyReason, repoTakenDown } from "../repos";
import { scopedRepoPermission, tokenCredential } from "../token-scope";
import {
  bypassesProtection,
  directUpdateViolation,
  forcePushViolation,
  loadProtections,
  protectionFor,
  tagProtectionFor,
  tagUpdateViolation,
} from "../protection";
import { findForcePushes } from "./force-push";
import type { BranchProtection } from "../protection";
import { triggerPush } from "../events/push-trigger";
import { isHiddenRef } from "./hidden-refs";
import {
  filterAdvertisement,
  filterLsRefs,
  inspectUploadRequest,
  MalformedUploadRequestError,
} from "./advertise-filter";
import { scanPushBody } from "../security/push-protection";
import { basicAuthHeader, forgetRepoToken, repoTokenSecret } from "./artifacts";
import { appliedCommands } from "./receive-report";
import { concatBytes, pktLine, readUntilFlush, reportStatusResponse } from "./pktline";
import { invalidateRefs } from "./refs";
import { ZERO_SHA } from "./store";
import { scratchGitPermission, scratchPushPolicy } from "../sites/scratch-git";
import { isScratchRepo } from "../sites/config";
import type { Permission, RepoRow, Viewer } from "~/lib/types";
import { randomId } from "../crypto";
import { countingBody, haveDetector, meterGitOp } from "../metering/git";
import { planBlockReason } from "../metering/quota";
import { captureServerEvent } from "../analytics";

const GIT_PATH = /^\/([^/]+)\/([^/]+?)(?:\.git)?\/(info\/refs|git-upload-pack|git-receive-pack)$/;