144 lines · 4.8 KB
import { all, batch, first, run, stmt } from "./db";
import { randomId } from "./crypto";
import { allocateIssueNumber } from "./issues";
import type { IssueRow } from "./issues";
import { addIssueEvent } from "./pulls";
import { requireRepoAccess } from "./repos";
import type { RepoAccess } from "./repos";
import { forbidden, notFoundError } from "./errors";
import type { Permission, Viewer } from "~/lib/types";

const MAX_CONVERTED_COMMENTS = 500;

export type DiscussionRow = {
  id: string;
  repo_id: string;
  number: number;
  category_id: string;
  author_id: string;
  title: string;
  body: string;
  answer_id: string | null;
  upvotes: number;
  comments_count: number;
  locked: number;
  created_at: number;
  updated_at: number;
};

export type CategoryRow = {
  id: string;
  repo_id: string;
  name: string;
  emoji: string;
  description: string;
  answerable: number;
};

const DEFAULT_CATEGORIES = [
  { name: "General", emoji: "💬", description: "Chat about anything", answerable: 0 },
  { name: "Q&A", emoji: "🙏", description: "Ask the community for help", answerable: 1 },