270 lines · 9.2 KB
import { env } from "cloudflare:workers";
import { batch, first, run, stmt } from "../db";
import { repoDb, stmt as scopedStmt } from "../scoped-db";
import { registerLocator } from "../scoped-db/locators";
import { scopedId } from "../scoped-db/ids";
import { registerRepoRows } from "../issue-scope";
import { randomId } from "../crypto";
import { allocateIssueNumber, applyLabels, indexIssue } from "../issues";
import { loadRepoById } from "../repos";
import { HttpError } from "../errors";
import { githubApi, installationToken } from "./github-app";
import { assertMirrorPullAllowed, isGithubRepoName } from "./github-sync";
import { loadIntegration, parseConfig } from "./store";

const PAGE_SIZE = 20;
const MAX_IMPORT_ITEMS = 2000;
const MAX_COMMENTS_PER_ITEM = 30;
const MAX_PAGE_BYTES = 2 * 1024 * 1024;
const MAX_BODY = 60_000;
const IMPORT_LABELS = [
  { name: "imported", color: "6e7681" },
  { name: "pull-request", color: "8957e5" },
];

export type ImportJobMessage = {
  kind: "integration.job";
  jobId: string;
  page: number;
};

type GithubIssue = {
  number: number;
  title: string;
  body: string | null;
  state: "open" | "closed";
  html_url: string;
  comments: number;
  created_at: string;
  closed_at: string | null;
  user: { login: string } | null;