web/repo: a signed-out reader's pull page finds a same-repo source branch in the sidebar
Signed-off-by: dawn <90008@klbr.net>
171 unmodified linesExpand all172173174175176177178179180181182183184185182183184185186187186187188189171 unmodified linesExpand all } };};
/** whether the sidebar lists every branch of the repo, so it can answer for them */export const holdsEveryBranch = (sidebar: RepoSidebar | null): sidebar is RepoSidebar => !!sidebar && !sidebar.failed.refs && sidebar.branches.length === sidebar.totalBranches;
/** every ref of the repo, from the sidebar when it holds them all */export const repoRefs = async ( sidebar: RepoSidebar | null | Promise<RepoSidebar | null>, read: () => Promise<{ tags: TagSummary[]; branches: BranchSummary[] }>): Promise<{ tags: TagSummary[]; branches: BranchSummary[] }> => { const held = await Promise.resolve(sidebar).catch(() => null); const whole = held && !held.failed.refs && held.branches.length === held.totalBranches && held.tags.length === held.totalTags; return whole ? { tags: held.tags, branches: held.branches } : read(); return holdsEveryBranch(held) && held.tags.length === held.totalTags ? { tags: held.tags, branches: held.branches } : read();};18 unmodified lines19202122232425262767 unmodified lines959697989899100101102103104105106107108109110111112113114115110 unmodified linesExpand all226227228229220230231232233234594 unmodified linesExpand all18 unmodified lines import { createPatch, deleteBranch } from "#lib/api/pull.ts"; import { editTicket, eraseTicket, setTicketState } from "#lib/api/ticket.ts"; import { gitTarget, hasGit } from "#lib/api/gitclient.ts"; import { repoBranches } from "#lib/api/repoIndex.ts"; import { holdsEveryBranch } from "#lib/api/repoSidebar.ts"; import { knotFor, resolveRepoByRepoDid, resolveRepoKnot } from "#lib/api/repo.ts"; import { rkeyFromUri } from "#lib/api/uri.ts"; import { loadDiff,67 unmodified lines const ctx = createBobbinClient({ serviceUrl: data.publicConfig.bobbinUrl }); const location = await resolveRepoByRepoDid(ctx, source.repo); return location ? `/${location.owner}/${location.name}` : undefined; }); // the branch tip isn't in the pull record. it has to be fetched live // the branch tip isn't in the pull record. a visitor only needs to know the branch is // there, which a same-repo pull's sidebar says; a signed-in reader may resubmit or delete // it, so they get the live tip const sourceHead = createLoad(async () => { const source = pull.source; if (!source) return undefined; if (!auth.currentDid && !isForkBased) { const sidebar = await Promise.resolve(data.currentSidebar ?? data.sidebar).catch( () => null ); if (holdsEveryBranch(sidebar)) return sidebar.branches.find((branch) => branch.name === source.branch)?.hash; } const bobbin = createBobbinClient({ serviceUrl: data.publicConfig.bobbinUrl, fetch: globalThis.fetch });110 unmodified linesExpand all // the sidebar names every branch of a repo with up to REF_LIMIT refs, past that the knot is asked const targetBranchLives = createLoad(async () => { if (!browser) return false; const sidebar = await Promise.resolve(data.sidebar).catch(() => null); if (sidebar && !sidebar.failed.refs && sidebar.branches.length === sidebar.totalBranches) if (holdsEveryBranch(sidebar)) return sidebar.branches.some((branch) => branch.name === pull.targetBranch); const targetRef = fetchTargetRef(); if (!targetRef) return false; try {594 unmodified linesExpand all