106 lines · 4.9 KB
import { HttpError } from "../errors";
import { createEditorSession } from "./editor";
import { apiContext } from "./http";
import type { ApiContext } from "./http";
import { createPull, getPull, listPulls, mergePull, updatePullBranch } from "./pulls";
import {
  createRepo,
  deleteRepo,
  forkRepo,
  getCollaborator,
  getRepo,
  importRepo,
  listRepos,
  putCollaborator,
  updateRepo,
} from "./repos";
import {
  approveRunApi,
  cancelRunApi,
  createRegistrationToken,
  deleteRunnerApi,
  listRunnersApi,
  listRunsApi,
  putRunnerPolicy,
} from "./runners";
import { createProtection, listProtections, putContents, setPushProtection } from "./settings";
import { getLfsUsage, getUser, listTokens, revokeToken } from "./user";

export const API_V1_PREFIX = "/api/v1/";

type Handler = (ctx: ApiContext, params: string[]) => Response | Promise<Response>;
type Route = { method: string; pattern: RegExp; handler: Handler };

const SEG = "([^/]+)";
const REPO = `/repos/${SEG}/${SEG}`;

function route(method: string, path: string, handler: Handler): Route {
  return { method, pattern: new RegExp(`^${path}$`), handler };
}