Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143<script lang="ts"> import type { Snippet } from "svelte"; import { resolve } from "$app/paths"; import { getAuth } from "#lib/auth.svelte.ts"; import { createBobbinClient } from "#lib/api/client.ts"; import { count } from "#lib/api/count.ts"; import { createLoad } from "#lib/action.svelte.ts"; import StepMarker from "#lib/components/ui/StepMarker.svelte"; import type { GitRepoInfo } from "#lib/components/repo/types.ts";
interface Props { repo: GitRepoInfo; /** * Overrides the SSH key lookup, for deterministic stories/tests or when preloaded. * Left unset in real usage, in which case it's figured out from the API. */ hasSshKey?: boolean; }
let { repo, hasSshKey }: Props = $props();
const auth = getAuth(); const isOwner = $derived(auth.currentDid === repo.ownerDid); // same host rewrite as the clone urls const sshHost = $derived( (repo.knot === "knot1.tangled.sh" ? "tangled.org" : repo.knot) .replace(/^[a-z]+:\/\//, "") .split(/[:/]/)[0] ); const remote = $derived(`git@${sshHost}:${repo.repoDid ?? `${repo.ownerHandle}/${repo.name}`}`);
const resolvedBranch = $derived(repo.git.defaultBranch);
// Only load on demand if hasSshKey was not provided const keyStatus = createLoad(async (): Promise<boolean | undefined> => { if (hasSshKey !== undefined) return hasSshKey; const owner = isOwner; const did = auth.currentDid; const serviceUrl = auth.bobbinUrl; if (!owner || !did) return undefined; try { const ctx = createBobbinClient({ serviceUrl }); const result = await count(ctx, "org.tangled.publicKey.countKeys", did); return result.count > 0; } catch { return false; } });
const ownerHasKey = $derived(hasSshKey !== undefined ? hasSshKey : keyStatus.data); const loadingKey = $derived( hasSshKey === undefined && (keyStatus.loading || keyStatus.data === undefined) );</script>
{#snippet step(n: number, text: Snippet)} <p class="flex items-center gap-xs"> <StepMarker>{n}</StepMarker> <span class="min-w-0">{@render text()}</span> </p>{/snippet}
{#snippet codeBlock(lines: string[])} <pre class="typography-monospace overflow-x-auto rounded-md bg-background-inset p-sm">{lines.join( "\n" )}</pre>{/snippet}
{#if isOwner} {#if loadingKey} <div class="pt-md pb-xl" aria-hidden="true"></div> {:else if ownerHasKey} <div class="flex w-full place-content-center"> <div class="flex w-fit max-w-full min-w-0 flex-col gap-lg px-md pt-md pb-xl"> <p data-testid="emptyRepoNote">This is an empty repository. You can either:</p> {#snippet createNew()} Create a new repository on the command line {/snippet} {#snippet pushExisting()} Or push an existing repository from the command line {/snippet} <div class="flex flex-col gap-xs"> {@render step(1, createNew)} {@render codeBlock([ `echo "# ${repo.name}" >> README.md`, "git init", "git add README.md", 'git commit -m "initial commit"', `git branch -M ${resolvedBranch}`, `git remote add origin ${remote}`, `git push -u origin ${resolvedBranch}` ])} </div> <div class="flex flex-col gap-xs"> {@render step(2, pushExisting)} {@render codeBlock([ `git remote add origin ${remote}`, `git branch -M ${resolvedBranch}`, `git push -u origin ${resolvedBranch}` ])} </div> </div> </div> {:else} <div class="flex w-full place-content-center"> <div class="flex w-fit max-w-full min-w-0 flex-col gap-md px-md pt-md pb-xl"> <p data-testid="emptyRepoNote">This is an empty repository. To get started:</p> {#snippet generateKey()} First, generate a new <a href="https://git-scm.com/book/en/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key" rel="noopener" class="underline">SSH key pair</a >. {/snippet} {#snippet addKey()} Then add the public key from the <a href={resolve("/settings/keys")} class="underline">keys page</a> in your settings. {/snippet} {#snippet configureRemote()} Configure your remote to <code class="rounded-md bg-background-inset px-2xs typography-monospace-regular break-all" >{remote}</code > {/snippet} {#snippet push()} Push! {/snippet} {@render step(1, generateKey)} {@render step(2, addKey)} {@render step(3, configureRemote)} {@render step(4, push)} </div> </div> {/if}{:else} <p data-testid="emptyRepoNote" class="py-xl text-center text-foreground-subtle"> This is an empty repository. </p>{/if}