201 lines · 5.5 KB
import { z } from "zod";
import { all, batch, first, run, stmt } from "../db";
import { randomId, randomToken, sha256Hex } from "../crypto";
import { badRequest, conflict, forbidden, notFoundError } from "../errors";
import { recordActivity } from "../events/emit";
import { branchSha, listRefs, resolveRevision } from "../git/refs";
import { ZERO_SHA } from "../git/store";
import {
  announcePush,
  assertDirectUpdate,
  rethrowPush,
} from "../git/web-commit";
import {
  createBranch as pushBranch,
  deleteRef,
  isValidRefName,
} from "../git/writer";
import { assertBelowCap, CAPS, limitWrite } from "../limits";
import { toProtection } from "../protection";
import type { BranchProtectionRow } from "../protection";
import { repoMoveStatements } from "../redirects";
import { canCreateInAccount } from "../repos";
import { syncSiteForRepo } from "../sites/sync";
import { DEPLOY_TOKEN_PREFIX } from "../token-scope";
import {
  noContent,
  ownerAccount,
  readJson,
  repoJson,
  requireAccountScope,
  requireScopedRepo,
} from "./http";
import type { ApiContext } from "./http";

const MAX_LISTED_REFS = 90;
const VISIBLE_TOKEN_CHARS = 6;
const DAY_MS = 24 * 60 * 60 * 1000;

export async function listBranchesApi(
  ctx: ApiContext,