Skip to content

Commit

Permalink
Make repositories table a bit skinnier by abbreviating git commit shas
Browse files Browse the repository at this point in the history
And also linkify commits, where the repository has such a URL template.
Personally, I'd prefer to be taken to the git _log_ at the given commit,
but all zoekt gives us is the commit detail URL, so.
  • Loading branch information
isker committed Oct 24, 2023
1 parent d0378bc commit b4807fb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-adults-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"neogrok": patch
---

Make repositories table a bit skinnier by abbreviating git commit shas
3 changes: 3 additions & 0 deletions src/lib/server/zoekt-list-repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const listResultSchema = v.object({
URL: v.string(),
LatestCommitDate: dateSchema,
FileURLTemplate: v.string(),
CommitURLTemplate: v.string(),
Branches: v.array(
v
.object({ Name: v.string(), Version: v.string() })
Expand All @@ -102,6 +103,7 @@ const listResultSchema = v.object({
URL,
LatestCommitDate,
FileURLTemplate,
CommitURLTemplate,
Branches,
}) => ({
name: Name,
Expand All @@ -110,6 +112,7 @@ const listResultSchema = v.object({
url: URL,
lastCommit: toISOStringWithoutMs(LatestCommitDate),
fileUrlTemplate: FileURLTemplate,
commitUrlTemplate: CommitURLTemplate,
branches: Branches,
}),
),
Expand Down
19 changes: 16 additions & 3 deletions src/routes/repositories/repository.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
lastCommit,
branches,
stats: { fileCount, indexBytes, contentBytes },
commitUrlTemplate,
} = repository);
// Abbreviate git hashes. Helps make the very wide table a bit narrower.
const abbreviateVersion = (v: string) =>
/^[a-z0-9]{40}$/.test(v) ? v.slice(0, 8) : v;
</script>

<tr class="border">
Expand All @@ -21,9 +26,17 @@
</td>
<td class="p-1">{fileCount}</td>
<td class="p-1">
{branches
.map(({ name: branchName, version }) => `${branchName}@${version}`)
.join(" ")}
{#each branches as { name: branchName, version }}
{branchName}@<span class="font-mono">
{#if commitUrlTemplate}
<Link to={commitUrlTemplate.replaceAll("{{.Version}}", version)}
>{abbreviateVersion(version)}</Link
>
{:else}
{abbreviateVersion(version)}
{/if}
</span>
{/each}
</td>
<td class="p-1">{prettyBytes(contentBytes, { space: false })}</td>
<td class="p-1">{prettyBytes(indexBytes, { space: false })}</td>
Expand Down

0 comments on commit b4807fb

Please sign in to comment.