Skip to content

Modern Docker Management, Designed for Everyone

fix: ssh git repos commit hash links incorrect (#1643)

Kyle Mendell4c5a3b16d980
diff --git a/frontend/src/lib/utils/git.ts b/frontend/src/lib/utils/git.ts
new file mode 100644
index 000000000..4e68f329c
--- /dev/null
+++ b/frontend/src/lib/utils/git.ts
@@ -0,0 +1,65 @@
+function stripGitSuffix(path: string): string {
+ return path.replace(/\.git\/?$/, '');
+}
+
+function trimTrailingSlash(value: string): string {
+ return value.replace(/\/+$/, '');
+}
+
+function commitSegmentForHost(hostname: string): string {
+ const host = hostname.toLowerCase();
+ if (host.includes('gitlab')) return '/-/commit/';
+ if (host.includes('bitbucket')) return '/commits/';
+ return '/commit/';
+}
+
+export function toGitWebUrl(raw: string): string | null {
+ const trimmed = raw.trim();
+ if (!trimmed) return null;
+
+ if (trimmed.includes('://')) {
+ try {
+ const parsed = new URL(trimmed);
+ if (!parsed.hostname) return null;
+ const path = stripGitSuffix(parsed.pathname);
+ if (!path || path === '/') return null;
+ const protocol = parsed.protocol === 'http:' || parsed.protocol === 'https:' ? parsed.protocol : 'https:';
+ return `${protocol}//${parsed.hostname}${path}`;
+ } catch {
+ return null;
+ }
+ }
+
+ const scpMatch = /^(?:.+@)?([^:\/]+):(.+)$/.exec(trimmed);
+ if (scpMatch) {
+ const host = scpMatch[1];
+ const path = stripGitSuffix(scpMatch[2].replace(/^\/+/, ''));
+ if (!host || !path) return null;
+ return `https://${host}/${path}`;
+ }
+
+ const hostPathMatch = /^([^\/]+)\/(.+)$/.exec(trimmed);
+ if (hostPathMatch) {
+ const host = hostPathMatch[1];
+ const path = stripGitSuffix(hostPathMatch[2].replace(/^\/+/, ''));
+ if (!host || !path) return null;
+ return `https://${host}/${path}`;
+ }
+
+ return null;
+}
+
+export function toGitCommitUrl(repositoryUrl: string, commit: string): string | null {
+ const base = toGitWebUrl(repositoryUrl);
+ const trimmedCommit = commit.trim();
+ if (!base || !trimmedCommit) return null;
+
+ const normalizedBase = trimTrailingSlash(base);
+ try {
+ const host = new URL(normalizedBase).hostname;
+ const segment = commitSegmentForHost(host);
+ return `${normalizedBase}${segment}${encodeURIComponent(trimmedCommit)}`;
+ } catch {
+ return null;
+ }
+}
diff --git a/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte b/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte
index e23104a9a..560ed3cfd 100644
--- a/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte
+++ b/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte
@@ -15,6 +15,7 @@
import { format } from 'date-fns';
import { m } from '$lib/paraglide/messages';
import { gitOpsSyncService } from '$lib/services/gitops-sync-service';
+ import { toGitCommitUrl } from '$lib/utils/git';
import {
EllipsisIcon,
EditIcon as PencilIcon,
@@ -241,11 +242,12 @@
{#snippet CommitCell({ value, item }: { value: any; item: GitOpsSync; row: Row<GitOpsSync> })}
{#if value}
+ {@const commitUrl = item.repository?.url ? toGitCommitUrl(item.repository.url, String(value)) : null}
<div class="flex items-center gap-1.5">
<HashIcon class="text-muted-foreground size-3.5" />
- {#if item.repository?.url}
+ {#if commitUrl}
<a
- href="{item.repository.url.replace(/\.git$/, '')}/commit/{value}"
+ href={commitUrl}
target="_blank"
class="hover:text-primary bg-muted text-muted-foreground rounded px-2 py-0.5 font-mono text-xs transition-colors"
>
diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
index 381835adc..cccb78443 100644
--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
@@ -19,6 +19,7 @@
import { z } from 'zod/v4';
import { createForm } from '$lib/utils/form.utils';
import { m } from '$lib/paraglide/messages';
+ import { toGitCommitUrl } from '$lib/utils/git';
import { toSafeHref } from '$lib/utils/url';
import { PersistedState } from 'runed';
import EditableName from '../components/EditableName.svelte';
@@ -345,11 +346,14 @@
</div>
<div class="text-muted-foreground flex flex-wrap items-center gap-4 text-xs sm:col-start-2">
{#if project.lastSyncCommit}
+ {@const commitUrl = project.gitRepositoryURL
+ ? toGitCommitUrl(project.gitRepositoryURL, project.lastSyncCommit)
+ : null}
<div class="flex items-center gap-1.5">
<span class="hidden sm:inline">{m.git_sync_commit()}:</span>
- {#if project.gitRepositoryURL}
+ {#if commitUrl}
<a
- href="{project.gitRepositoryURL.replace(/\.git$/, '')}/commit/{project.lastSyncCommit}"
+ href={commitUrl}
target="_blank"
class="hover:text-primary sm:bg-muted font-mono transition-colors sm:rounded sm:px-1.5 sm:py-0.5"
>
@@ -425,11 +429,14 @@
<br />
<div class="mt-2 flex flex-col gap-1">
{#if project.lastSyncCommit}
+ {@const commitUrl = project.gitRepositoryURL
+ ? toGitCommitUrl(project.gitRepositoryURL, project.lastSyncCommit)
+ : null}
<div class="flex items-center gap-1.5 font-mono text-xs">
<span class="text-muted-foreground">{m.git_sync_commit()}:</span>
- {#if project.gitRepositoryURL}
+ {#if commitUrl}
<a
- href="{project.gitRepositoryURL.replace(/\.git$/, '')}/commit/{project.lastSyncCommit}"
+ href={commitUrl}
target="_blank"
class="bg-muted hover:text-primary rounded px-1.5 py-0.5 transition-colors"
>