import type * as getCompare from '#lib/lexicons/dev/knotless/getCompare.ts'; import type * as getTemplate from '#lib/lexicons/dev/knotless/getTemplate.ts'; import type * as listBranches from '#lib/lexicons/dev/knotless/listBranches.ts'; import type { PageLoad } from './$types'; import type { AtUriString } from '@atproto/lex'; import { branches, repoPage, xrpc } from '#lib/data.ts'; /** * Opening a pull: the branch to merge into * (`?base=`, the default branch if not given), the repository to bring a * branch in from (`?head=`, this one or a fork) and the branch * (`?branch=`); what it brings in, once chosen; and the template a pull * there is asked to follow. With `?expand=1`, as a branch's Compare & pull * links, the form to open it shows at once rather than on asking. */ export const load: PageLoad = async (event) => { const p = event.url.searchParams; const { repo, answer } = await repoPage(event, 'dev.knotless.getCompare'); const base = p.get('base') || repo.defaultBranch; const head = (p.get('head') || repo.uri) as AtUriString; const branch = p.get('branch') || ''; const quiet = { ...event, setHeaders: () => {} }; const [bases, from, compared, template] = await Promise.all([ branches(event), xrpc( quiet, 'dev.knotless.listBranches', { repo: head, limit: 1000 }, true ), branch ? xrpc( quiet, 'dev.knotless.getCompare', { repo: repo.uri, base, head, branch }, true ) : null, xrpc( quiet, 'dev.knotless.getTemplate', { repo: repo.uri, kind: 'pull', base }, true ).catch(() => null) ]); return { repo, heads: answer.heads, base, head, branch, bases, branches: from?.branches.map((b) => b.name) ?? [], changes: compared?.changes ?? null, template: template?.template ?? '', expand: p.get('expand') === '1' }; };