Skip to content

Modern Docker Management, Designed for Everyone

feat: link Git-managed projects and synced files to their repository (#3879)

Fussel6eed748e3fc9
diff --git a/frontend/messages/en.json b/frontend/messages/en.json
index 53d975e0b..cca0289a5 100644
--- a/frontend/messages/en.json
+++ b/frontend/messages/en.json
@@ -1932,6 +1932,8 @@
"git_managed_env_note": "The environment file (.env) can still be edited in Arcane to provide runtime configuration.",
"git_from_git_repo": "From Git Repo",
"git_sync_from_git": "Sync from Git",
+ "git_open_project_in_repository": "Open Project in Git",
+ "git_edit_file_in_repository": "Edit File in Git",
"git_sync_file_limits_title": "Git Sync File Limits",
"git_sync_file_limits_description": "Apply environment-wide caps when Arcane copies repository files during Git syncs. Use 0 to remove a cap.",
"git_sync_max_files_label": "Max Synced Files",
diff --git a/frontend/src/lib/components/code-panel.svelte b/frontend/src/lib/components/code-panel.svelte
index ad92cf19c..590072897 100644
--- a/frontend/src/lib/components/code-panel.svelte
+++ b/frontend/src/lib/components/code-panel.svelte
@@ -41,7 +41,8 @@
outlineOpen = $bindable(false),
diffOpen = $bindable(false),
commandPaletteOpen = $bindable(false),
- variant = 'card'
+ variant = 'card',
+ gitEditUrl
}: {
title: string;
open?: boolean;
@@ -62,14 +63,42 @@
diffOpen?: boolean;
commandPaletteOpen?: boolean;
variant?: 'card' | 'plain';
+ gitEditUrl?: string | null;
} = $props();
const isMobile = new IsMobile();
const effectiveAutoHeight = $derived(autoHeight || isMobile.current);
+ const editUrl = $derived(readOnly && !(enableDiff && diffOpen) && gitEditUrl ? gitEditUrl : null);
+
+ // CodeMirror's gutters, search panel and tooltips share this wrapper.
+ function isEditorText(target: EventTarget | null): boolean {
+ return target instanceof Element && !!target.closest('.cm-content');
+ }
+
+ function handleEditorClick(event: MouseEvent) {
+ if (!editUrl || !isEditorText(event.target)) return;
+ if (!window.getSelection()?.isCollapsed) return;
+ window.open(editUrl, '_blank', 'noopener,noreferrer');
+ }
+
+ function handleEditorKeydown(event: KeyboardEvent) {
+ if (!editUrl || event.key !== 'Enter') return;
+ if (event.target !== event.currentTarget && !isEditorText(event.target)) return;
+ event.preventDefault();
+ window.open(editUrl, '_blank', 'noopener,noreferrer');
+ }
</script>
{#snippet editorBody()}
- <div class="{effectiveAutoHeight ? '' : 'relative flex-1'} min-h-0 w-full min-w-0">
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
+ <div
+ class="{effectiveAutoHeight ? '' : 'relative flex-1'} min-h-0 w-full min-w-0 {editUrl ? 'cursor-pointer' : ''}"
+ role={editUrl ? 'link' : undefined}
+ tabindex={editUrl ? 0 : undefined}
+ title={editUrl ? m.git_edit_file_in_repository() : undefined}
+ onclick={handleEditorClick}
+ onkeydown={handleEditorKeydown}
+ >
<div class={effectiveAutoHeight ? '' : 'absolute inset-0'}>
<CodeEditor
bind:value
diff --git a/frontend/src/lib/utils/gitops.ts b/frontend/src/lib/utils/gitops.ts
new file mode 100644
index 000000000..73c7d8e6d
--- /dev/null
+++ b/frontend/src/lib/utils/gitops.ts
@@ -0,0 +1,33 @@
+import type { GitOpsSync } from '#lib/types/automation.js';
+import { toGitRouteUrl, toGitWebUrl } from '#lib/utils/navigation.js';
+
+function composeDirectory(sync: GitOpsSync): string {
+ return sync.composePath.split('/').slice(0, -1).join('/');
+}
+
+// Mirrors the backend's workspace lock, which deliberately omits the project-root .env.
+function syncedPaths(sync: GitOpsSync): string[] {
+ try {
+ const parsed: unknown = JSON.parse(sync.syncedFiles ?? '[]');
+ return Array.isArray(parsed) ? parsed.filter((entry) => typeof entry === 'string' && entry) : [];
+ } catch {
+ return [];
+ }
+}
+
+// Unknown forges still get a link to the repository itself.
+export function gitOpsProjectUrl(sync: GitOpsSync | undefined | null): string | null {
+ if (!sync?.repository?.url) return null;
+ return toGitRouteUrl(sync.repository.url, 'tree', sync.branch, composeDirectory(sync)) ?? toGitWebUrl(sync.repository.url);
+}
+
+export function gitOpsComposeEditUrl(sync: GitOpsSync | undefined | null): string | null {
+ if (!sync?.repository?.url) return null;
+ return toGitRouteUrl(sync.repository.url, 'edit', sync.branch, sync.composePath);
+}
+
+export function gitOpsFileEditUrl(sync: GitOpsSync | undefined | null, relativePath: string): string | null {
+ if (!sync?.repository?.url || !syncedPaths(sync).includes(relativePath)) return null;
+ const directory = composeDirectory(sync);
+ return toGitRouteUrl(sync.repository.url, 'edit', sync.branch, directory ? `${directory}/${relativePath}` : relativePath);
+}
diff --git a/frontend/src/lib/utils/navigation.ts b/frontend/src/lib/utils/navigation.ts
index 02e55dbcf..e6cd42187 100644
--- a/frontend/src/lib/utils/navigation.ts
+++ b/frontend/src/lib/utils/navigation.ts
@@ -167,22 +167,21 @@ export function toSafeHref(raw: string, scheme: string = 'https'): string {
// --- Git URL helpers ---
+type GitRoute = 'commit' | 'tree' | 'blob' | 'edit';
+
function stripGitSuffix(path: string): string {
- return path.replace(/\.git\/?$/, '');
+ return path.replace(/\.git\/?$/, '').replace(/\/+$/, '');
}
-function trimTrailingSlash(value: string): string {
- return value.replace(/\/+$/, '');
+function encodePathSegments(value: string): string {
+ return value
+ .split('/')
+ .filter(Boolean)
+ .map((segment) => encodeURIComponent(segment))
+ .join('/');
}
-function commitSegmentForHost(hostname: string): string {
- const host = hostname.toLowerCase();
- if (host.includes('gitlab')) return '/-/commit/';
- if (host.includes('bitbucket')) return '/commits/';
- return '/commit/';
-}
-
-function toGitWebUrl(raw: string): string | null {
+export function toGitWebUrl(raw: string): string | null {
const trimmed = raw.trim();
if (!trimmed) return null;
@@ -192,8 +191,11 @@ function toGitWebUrl(raw: string): string | null {
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}`;
+ const isWebProtocol = parsed.protocol === 'http:' || parsed.protocol === 'https:';
+ const protocol = isWebProtocol ? parsed.protocol : 'https:';
+ // An ssh:// port is the SSH port, not the forge's web port.
+ const host = isWebProtocol ? parsed.host : parsed.hostname;
+ return `${protocol}//${host}${path}`;
} catch {
return null;
}
@@ -208,16 +210,30 @@ function toGitWebUrl(raw: string): string | null {
return path ? `https://${host}/${path}` : null;
}
-export function toGitCommitUrl(repositoryUrl: string, commit: string): string | null {
+// Only hostnames that name their product are recognized; a self-hosted forge on a neutral domain gets no deep link.
+function gitRouteSegment(hostname: string, route: GitRoute): string | null {
+ const host = hostname.toLowerCase();
+ if (host.includes('gitlab')) return `/-/${route}/`;
+ // Bitbucket has no dedicated edit route; /src/ opens the file with its own edit action.
+ if (host.includes('bitbucket')) return route === 'commit' ? '/commits/' : '/src/';
+ if (host.includes('gitea') || host.includes('forgejo') || host.includes('codeberg')) {
+ if (route === 'edit') return '/_edit/';
+ return route === 'commit' ? '/commit/' : '/src/branch/';
+ }
+ if (host.includes('github') || route === 'commit') return `/${route}/`;
+ return null;
+}
+
+export function toGitRouteUrl(repositoryUrl: string, route: GitRoute, ref: string, path = ''): string | null {
const base = toGitWebUrl(repositoryUrl);
- const trimmedCommit = commit.trim();
- if (!base || !trimmedCommit) return null;
+ const encodedRef = encodePathSegments(ref.trim());
+ if (!base || !encodedRef) return null;
- const normalizedBase = trimTrailingSlash(base);
try {
- const host = new URL(normalizedBase).hostname;
- const segment = commitSegmentForHost(host);
- return `${normalizedBase}${segment}${encodeURIComponent(trimmedCommit)}`;
+ const segment = gitRouteSegment(new URL(base).hostname, route);
+ if (!segment) return null;
+ const encodedPath = encodePathSegments(path);
+ return `${base}${segment}${encodedRef}${encodedPath ? `/${encodedPath}` : ''}`;
} 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 11498bf12..886c66d32 100644
--- a/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte
+++ b/frontend/src/routes/(app)/environments/[id]/gitops/sync-table.svelte
@@ -15,7 +15,7 @@
import { formatDateTimeShort } from '#lib/utils/formatting.js';
import { m } from '#lib/paraglide/messages.js';
import { gitOpsSyncService } from '#lib/services/gitops-sync-service.js';
- import { toGitCommitUrl } from '#lib/utils/navigation.js';
+ import { toGitRouteUrl } from '#lib/utils/navigation.js';
import {
EditIcon as PencilIcon,
StartIcon as PlayIcon,
@@ -210,10 +210,22 @@
</div>
{/snippet}
-{#snippet PathCell({ value }: { value: any; item: GitOpsSync; row: ArcaneRow<GitOpsSync> })}
+{#snippet PathCell({ value, item }: { value: any; item: GitOpsSync; row: ArcaneRow<GitOpsSync> })}
+ {@const fileUrl = item.repository?.url ? toGitRouteUrl(item.repository.url, 'blob', item.branch, String(value)) : null}
<div class="flex items-center gap-1.5">
<FolderIcon class="size-3.5 text-muted-foreground" />
- <code class="rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground">{value}</code>
+ {#if fileUrl}
+ <a
+ href={fileUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ class="rounded bg-muted px-2 py-0.5 font-mono text-xs text-muted-foreground transition-colors hover:text-primary"
+ >
+ {value}
+ </a>
+ {:else}
+ <code class="rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground">{value}</code>
+ {/if}
</div>
{/snippet}
@@ -235,7 +247,7 @@
{#snippet CommitCell({ value, item }: { value: any; item: GitOpsSync; row: ArcaneRow<GitOpsSync> })}
{#if value}
- {@const commitUrl = item.repository?.url ? toGitCommitUrl(item.repository.url, String(value)) : null}
+ {@const commitUrl = item.repository?.url ? toGitRouteUrl(item.repository.url, 'commit', String(value)) : null}
<div class="flex items-center gap-1.5">
<HashIcon class="size-3.5 text-muted-foreground" />
{#if commitUrl}
diff --git a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
index de2d2367e..baa383fcb 100644
--- a/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
+++ b/frontend/src/routes/(app)/projects/[projectId]/+page.svelte
@@ -18,6 +18,7 @@
GlobeIcon,
CodeIcon,
ArrowsUpDownIcon,
+ ExternalLinkIcon,
SearchIcon
} from '#lib/icons/index.js';
import { type TabItem } from '#lib/components/tab-bar/index.js';
@@ -35,8 +36,8 @@
import { z } from 'zod/v4';
import { createForm } from '#lib/utils/settings.js';
import { m } from '#lib/paraglide/messages.js';
- import { toGitCommitUrl } from '#lib/utils/navigation.js';
- import { toSafeHref } from '#lib/utils/navigation.js';
+ import { gitOpsComposeEditUrl, gitOpsFileEditUrl, gitOpsProjectUrl } from '#lib/utils/gitops.js';
+ import { toGitRouteUrl, toSafeHref } from '#lib/utils/navigation.js';
import { PersistedState } from 'runed';
import { useUrlTab } from '#lib/hooks/use-url-tab.svelte.js';
import ComposeFileEditorPanel from '#lib/components/compose-file-editor-panel.svelte';
@@ -293,6 +294,9 @@
// The override editor surfaces only when an override exists or the user asked
// to add one this session; otherwise the UI shows an "add override" affordance.
let overrideActive = $derived(overrideExists || overrideEditorRequested);
+ const gitProjectUrl = $derived(gitOpsProjectUrl(lifecycleSync));
+ const gitComposeEditUrl = $derived(gitOpsComposeEditUrl(lifecycleSync));
+ const gitOverrideEditUrl = $derived(gitOpsFileEditUrl(lifecycleSync, overrideFileName));
const projectWorkspaceLeadingRows = $derived([
{ key: 'compose', label: composeFileName, iconClass: 'text-blue-500', locked: true },
...(overrideActive
@@ -1369,7 +1373,8 @@
fileId: `project:${projectId}:compose`,
originalValue: serverComposeContent,
enableDiff: true,
- editorContext: codeEditorContext
+ editorContext: codeEditorContext,
+ gitEditUrl: gitComposeEditUrl
} as const;
}
@@ -1383,7 +1388,8 @@
fileId: `project:${projectId}:override`,
originalValue: serverOverrideContent,
enableDiff: true,
- editorContext: codeEditorContext
+ editorContext: codeEditorContext,
+ gitEditUrl: gitOverrideEditUrl
} as const;
}
@@ -1544,6 +1550,7 @@
value={selectedProjectWorkspaceMetadata.content ?? ''}
readOnly={true}
editorContext={codeEditorContext}
+ gitEditUrl={gitOpsFileEditUrl(lifecycleSync, relativePath)}
/>
{:else if projectWorkspaceContents[relativePath] === undefined}
<div class="flex h-full min-h-0 items-center justify-center text-muted-foreground">
@@ -1730,6 +1737,7 @@
originalValue={serverIncludeFiles[includeFile.relativePath] ?? ''}
enableDiff={true}
editorContext={codeEditorContext}
+ gitEditUrl={gitOpsFileEditUrl(lifecycleSync, includeFile.relativePath)}
/>
{:else if dirFile && loadedDirectoryFileContents[dirFile.relativePath] !== undefined}
<CodePanel
@@ -1775,18 +1783,30 @@
</div>
</Alert.Description>
</div>
- {#if canUpdateProject}
- <ArcaneButton
- action="base"
- tone="outline-primary"
- loading={isLoading.syncing}
- onclick={handleSyncFromGit}
- icon={RefreshIcon}
- customLabel={m.git_sync_from_git()}
- loadingLabel={m.common_syncing()}
- class="shrink-0"
- />
- {/if}
+ <div class="flex shrink-0 flex-wrap items-center gap-2">
+ {#if gitProjectUrl}
+ <ArcaneButton
+ action="base"
+ tone="outline"
+ href={gitProjectUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ icon={ExternalLinkIcon}
+ customLabel={m.git_open_project_in_repository()}
+ />
+ {/if}
+ {#if canUpdateProject}
+ <ArcaneButton
+ action="base"
+ tone="outline-primary"
+ loading={isLoading.syncing}
+ onclick={handleSyncFromGit}
+ icon={RefreshIcon}
+ customLabel={m.git_sync_from_git()}
+ loadingLabel={m.common_syncing()}
+ />
+ {/if}
+ </div>
</div>
</Alert.Root>
{/if}
@@ -2023,7 +2043,9 @@
{/if}
{#if project.lastSyncCommit}
- {@const commitUrl = project.gitRepositoryURL ? toGitCommitUrl(project.gitRepositoryURL, project.lastSyncCommit) : null}
+ {@const commitUrl = project.gitRepositoryURL
+ ? toGitRouteUrl(project.gitRepositoryURL, 'commit', project.lastSyncCommit)
+ : null}
<div class="mt-1 flex flex-wrap items-center gap-4 text-xs text-muted-foreground">
<div class="flex items-center gap-1.5">
<span class="hidden sm:inline">{m.commit()}:</span>