Vectrum
Sign In
23 lines · 1004 Bytes · TypeScript
import "server-only";
import { cache } from "react";
import { notFound } from "next/navigation";
import { getPull, pullCommits, pullDiff } from "./pulls";
import { getRepo } from "./repo";

/** A pull request for its pages (layout and tabs share one load), or the 404 page. */
export const getPullForPage = cache(async (owner: string, repoParam: string, numberParam: string) => {
  const repo = await getRepo(owner, repoParam);
  const pr = await getPull(repo.id, Number(numberParam));
  if (!pr) notFound();
  return { repo, pr, href: `${repo.base}/pulls/${pr.number}` };
});

export const getPullCommits = cache(async (owner: string, repoParam: string, numberParam: string) => {
  const { repo, pr } = await getPullForPage(owner, repoParam, numberParam);
  return pullCommits(repo, pr);
});

export const getPullFiles = cache(async (owner: string, repoParam: string, numberParam: string) => {
  const { repo, pr } = await getPullForPage(owner, repoParam, numberParam);
  return pullDiff(repo, pr);
});