From 3d44b392b314baa4cb5e02cd143ae0cd9ae7a9bb Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Thu, 20 Aug 2026 01:53:46 +0900 Subject: [PATCH] web: render PR with no submissions Signed-off-by: Seongmin Lee --- web/src/lib/api/pullRoute.test.ts | 9 ++ web/src/lib/api/pullRoute.ts | 10 +- .../[handle]/[repo]/pulls/[aturi]/+layout.ts | 2 - .../[repo]/pulls/[aturi]/[version]/+layout.ts | 3 +- .../[aturi]/[version]/[[range]]/+page.svelte | 105 ++++++++++++------ .../[aturi]/[version]/[[range]]/+page.ts | 6 +- 6 files changed, 90 insertions(+), 45 deletions(-) diff --git a/web/src/lib/api/pullRoute.test.ts b/web/src/lib/api/pullRoute.test.ts index e10850ffe..656ffde45 100644 --- a/web/src/lib/api/pullRoute.test.ts +++ b/web/src/lib/api/pullRoute.test.ts @@ -51,6 +51,15 @@ describe("parseDiffRoute", () => { expect(view("1", "base..head")).toMatchObject({ base: "b1", head: "h1" }); }); + it("resolves an empty version list instead of bouncing latest back to itself", () => { + expect(parseDiffRoute([], "latest")).toEqual({ + mode: "diff", + version: 0, + base: "", + head: "" + }); + }); + it("redirects a bad version to latest and a bad range to the version", () => { expect(parseDiffRoute(versions, "9")).toEqual({ redirect: "latest" }); expect(parseDiffRoute(versions, "foo")).toEqual({ redirect: "latest" }); diff --git a/web/src/lib/api/pullRoute.ts b/web/src/lib/api/pullRoute.ts index 3d5770414..a2b8e14c3 100644 --- a/web/src/lib/api/pullRoute.ts +++ b/web/src/lib/api/pullRoute.ts @@ -86,8 +86,10 @@ export const parseDiffRoute = ( rangeParam?: string ): PullDiffView | PullRouteRedirect => { const version = - versionParam === "latest" ? versions.length - 1 : index(versionParam, versions.length); - if (version === null || version < 0) return { redirect: "latest" }; + versionParam === "latest" + ? Math.max(versions.length - 1, 0) + : index(versionParam, versions.length); + if (version === null) return { redirect: "latest" }; const spec = parseRange(rangeParam ?? ""); if (!spec) return { redirect: "version" }; @@ -97,7 +99,7 @@ export const parseDiffRoute = ( return { mode: "diff", version, - base: isDiffBase ? versions[version].base : spec.base, - head: isDiffHead ? versions[version].head : spec.head + base: isDiffBase ? (versions[version]?.base ?? "") : spec.base, + head: isDiffHead ? (versions[version]?.head ?? "") : spec.head }; }; diff --git a/web/src/routes/[handle]/[repo]/pulls/[aturi]/+layout.ts b/web/src/routes/[handle]/[repo]/pulls/[aturi]/+layout.ts index 449803bf3..f19e8e38f 100644 --- a/web/src/routes/[handle]/[repo]/pulls/[aturi]/+layout.ts +++ b/web/src/routes/[handle]/[repo]/pulls/[aturi]/+layout.ts @@ -42,8 +42,6 @@ export const load: LayoutLoad = async (event) => { // const pullVersions = listPullVersions(aturi) if (!pullView) error(404, "Pull request not found"); - if (!pullView.versions.length) - error(404, "This pull request has no ref-based versions to show"); const body = pullView.body?.text ?? ""; const bodyHtml = body ? await renderMarkup(body, markup).catch(() => null) : null; diff --git a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts index 4fc545d75..c48bc02f9 100644 --- a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts +++ b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/+layout.ts @@ -24,7 +24,8 @@ export const load: LayoutLoad = async (event) => { }); // TODO: bobbin should hydrate the commit list with backlinked comment counts - const commits = await listLog(ctx, sourceRepoDid as Did, pull.versions[route.version]); + const version = pull.versions[route.version]; + const commits = version ? await listLog(ctx, sourceRepoDid as Did, version) : []; const commentCounts = countCommentsByCommit(parent.comments); return { diff --git a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.svelte b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.svelte index c0c83aaf8..b9d2f1e1f 100644 --- a/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.svelte +++ b/web/src/routes/[handle]/[repo]/pulls/[aturi]/[version]/[[range]]/+page.svelte @@ -383,47 +383,80 @@ - -
- - {#snippet actions()} - {#if isAuthor && pullState === "open" && sourceBranch} + {#if pull.versions.length} + +
+ + {#snippet actions()} + {#if isAuthor && pullState === "open" && sourceBranch} + + {/if} - {/if} -
+ {:else} +
+

+ This pull request has no versions submitted yet. +

+ {#if isAuthor && pullState === "open" && sourceBranch} +

+ Submit from + {sourceBranch} + to attach one. +

+ - {/snippet} - - - {#if isInterdiff} - - {:else} - - {/if} -
+ {/if} + +
+ {/if} - + {#if pull.versions.length} + + {/if} {#if discussionOpen}
{ if (route.mode === "diff") { route.base = commits.find((commit) => commit.hash.startsWith(route.base))?.hash ?? - currentVersion.base; + currentVersion?.base ?? + ""; route.head = commits.find((commit) => commit.hash.startsWith(route.head))?.hash ?? - currentVersion.head; + currentVersion?.head ?? + ""; } else if (route.mode === "interdiff" && route.changeId) { route.changeId = commits.find((commit) => commit.changeId?.startsWith(route.changeId))?.changeId ?? ""; -- 2.51.2