fork page
3984 unmodified linesExpand all39853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007399439953984 unmodified linesExpand all color: #f3f4f6; /* text-gray-100 */ }}
.untangled-fork-step .untangled-timeline-circle { top: 4px;}
.untangled-fork-step-title { min-height: 25px; display: flex; align-items: center;}
.untangled-repo-form-submit { margin-top: 1rem;}
/* Checkbox specific overrides to prevent extra layout padding */.untangled-checkbox { padding: 0 !important; margin: 0 !important;}
4 unmodified lines567891011121352 unmodified lines666768697071727374757677764 unmodified linesimport { BlobPage, CommitPage, CommitsPage, ForkRepoPage, IssuePage, IssuesPage, NewIssuePage, NewPullPage,52 unmodified lines <Route path="/pulls" component={PullsPage} /> <Route path="/commits" component={CommitsPage} /> <Route path="/commits/:ref" component={CommitsPage} /> <Route path="/commit/:ref" component={CommitPage} /> <Route path="/fork" component={ForkRepoPage} /> <Route path="/blob/:ref/*path" component={BlobPage} /> <Route path="/tree/:ref/*path" component={RepoCodePage} /> </Route> <Route path="/:actor" component={ProfilePage} /> <Route path="*404" component={NotFoundPage} /> </Router>);
32 unmodified lines333435363738394041101 unmodified linesExpand all32 unmodified lines getRepoTree, listRepoRecords, compareFork, createHiddenRef, forkRepo, getRepoForkCount,} from './api/repos';export { createRepoStar,101 unmodified linesExpand all123456export { BlobPage, RepoCodePage } from './repo/code';export { CommitPage, CommitsPage } from './repo/commits';export { ForkRepoPage } from './repo/fork';export { IssuePage, IssuesPage, NewIssuePage } from './repo/issues';export { NewPullPage, PullPage, PullsPage } from './repo/pulls';export { NewRepoPage } from './repo/new';747 unmodified linesExpand all7487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827831 unmodified line78578678778876176276378979079179279379437 unmodified lines832833834835809810811812813814815816817818819836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907747 unmodified linesExpand all
return records;};
const cleanedRepoName = (name: string): string => { const repoName = name.trim(); return repoName.endsWith('.git') ? repoName.slice(0, -4) : repoName;};
const repoRkeyFromName = (name: string): string => cleanedRepoName(name).toLowerCase();
const forkSourceUrl = (sourceRepo: RepoContext): string => `${normalizeServiceUrl(sourceRepo.knot).replace(/\/+$/, '')}/${sourceRepo.repoDid}`;
const deleteRepoFromKnot = async ( agent: OAuthUserAgent, knot: string, rkey: string,): Promise<void> => { const knotDeleteClient = await createServiceAuthRpc(agent, knot, 'sh.tangled.repo.delete'); await ok( knotDeleteClient.post('sh.tangled.repo.delete', { input: { did: agent.sub, name: rkey, rkey, }, as: null, }), );};
export const createRepo = async ( agent: OAuthUserAgent, input: { name: string;1 unmodified line defaultBranch: string; knot: string; },): Promise<RecordCreationResult> => { const repoName = input.name.trim(); const cleanedName = repoName.endsWith('.git') ? repoName.slice(0, -4) : repoName; const rkey = cleanedName.toLowerCase(); const cleanedName = cleanedRepoName(input.name); const rkey = repoRkeyFromName(input.name);
const knotClient = await createServiceAuthRpc(agent, input.knot, 'sh.tangled.repo.create'); const createResult = (await ok( knotClient.post('sh.tangled.repo.create', {37 unmodified lines rkey: parseAtUri(result.uri).rkey, }; } catch (pdsErr) { try { const knotDeleteClient = await createServiceAuthRpc(agent, input.knot, 'sh.tangled.repo.delete'); await ok( knotDeleteClient.post('sh.tangled.repo.delete', { input: { did: agent.sub, name: rkey, rkey: rkey, }, as: null, }), ); await deleteRepoFromKnot(agent, input.knot, rkey); } catch (deleteErr) { console.error('Failed to clean up repo on knot:', deleteErr); } throw pdsErr; }};
export const forkRepo = async ( agent: OAuthUserAgent, input: { sourceRepo: RepoContext; name: string; description?: string; knot: string; },): Promise<RecordCreationResult> => { const cleanedName = cleanedRepoName(input.name); const rkey = repoRkeyFromName(input.name);
const knotClient = await createServiceAuthRpc(agent, input.knot, 'sh.tangled.repo.create'); const createResult = (await ok( knotClient.post('sh.tangled.repo.create', { input: { rkey, name: rkey, source: forkSourceUrl(input.sourceRepo), }, }), )) as { repoDid?: string };
const repoDid = createResult.repoDid; if (!repoDid) { throw new Error('Knot failed to mint a repo DID.'); }
const pdsRpc = createAuthRpc(agent); const record = { $type: 'sh.tangled.repo', name: cleanedName, knot: input.knot, repoDid, source: input.sourceRepo.repoDid || input.sourceRepo.record.uri, description: input.description?.trim() || '', createdAt: new Date().toISOString(), };
try { const result = await ok( pdsRpc.post('com.atproto.repo.createRecord', { input: { repo: agent.sub, collection: REPO_COLLECTION, rkey, record, }, }), );
return { uri: result.uri, rkey: parseAtUri(result.uri).rkey, }; } catch (pdsErr) { try { await deleteRepoFromKnot(agent, input.knot, rkey); } catch (deleteErr) { console.error('Failed to clean up fork on knot:', deleteErr); } throw pdsErr; }};123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314import { A, useNavigate } from '@solidjs/router';import { createQuery, useQueryClient } from '@tanstack/solid-query';import { GitFork, Info, LoaderCircle } from 'lucide-solid';import { For, Match, Show, Switch, createEffect, createMemo, createSignal, type Component } from 'solid-js';
import { Avatar, ErrorState, LoadingState, cardStyles } from '../../components/common';import { resolveActor } from '../../lib/api/identity';import { forkRepo, listRepoRecords, listUserKnots } from '../../lib/api/repos';import { useAuth } from '../../lib/auth';import { getErrorMessage } from '../../lib/repo-utils';import { validateRepoName } from './new';import { useRepoQuery } from './shared';
export const ForkRepoPage: Component = () => { const auth = useAuth(); const navigate = useNavigate(); const queryClient = useQueryClient(); const repoQuery = useRepoQuery();
const [name, setName] = createSignal(''); const [description, setDescription] = createSignal(''); const [selectedKnot, setSelectedKnot] = createSignal(''); const [saving, setSaving] = createSignal(false); const [error, setError] = createSignal<string | null>(null); const [initializedForRepo, setInitializedForRepo] = createSignal<string | null>(null);
const viewerQuery = createQuery(() => ({ queryKey: ['viewer', auth.currentDid()], enabled: Boolean(auth.currentDid()), queryFn: async () => resolveActor(auth.currentDid()!), }));
const knotsQuery = createQuery(() => ({ queryKey: ['knots', auth.currentDid()], enabled: Boolean(auth.currentDid()), queryFn: async () => listUserKnots(auth.currentDid()!), }));
createEffect(() => { const repo = repoQuery.data; if (!repo || initializedForRepo() === repo.repoDid) { return; }
setName(repo.slug); setDescription(repo.record.value.description ?? ''); setInitializedForRepo(repo.repoDid); });
createEffect(() => { const knots = knotsQuery.data; if (knots && knots.length === 1) { setSelectedKnot(knots[0]); } });
const descriptionLength = createMemo(() => description().length); const viewerLabel = createMemo(() => viewerQuery.data?.handle || auth.currentDid() || '');
const handleSubmit = async (event: SubmitEvent) => { event.preventDefault();
const agent = auth.agent(); const currentDid = auth.currentDid(); const sourceRepo = repoQuery.data; if (!agent || !currentDid || !sourceRepo) return;
const repoName = name().trim(); const nameError = validateRepoName(repoName); if (nameError) { setError(nameError); return; }
if (description().length > 140) { setError('description must be 140 characters or fewer.'); return; }
const knot = selectedKnot(); if (!knot) { setError('please select a knot.'); return; }
setSaving(true); setError(null);
try { const existingRecords = await queryClient.fetchQuery({ queryKey: ['profile-repos', currentDid], queryFn: () => listRepoRecords(currentDid), });
const cleanedName = repoName.endsWith('.git') ? repoName.slice(0, -4) : repoName; const rkey = cleanedName.toLowerCase(); const exists = existingRecords.some( (record) => record.rkey.toLowerCase() === rkey || record.value.name?.trim().toLowerCase() === rkey, );
if (exists) { setError(`you already have a repository named "${cleanedName}".`); setSaving(false); return; }
const result = await forkRepo(agent, { sourceRepo, name: repoName, description: description(), knot, });
await Promise.all([ queryClient.invalidateQueries({ queryKey: ['profile-repos', currentDid] }), queryClient.invalidateQueries({ queryKey: ['repo-fork-count', sourceRepo.repoDid] }), ]);
navigate(`/${viewerLabel() || currentDid}/${result.rkey}`); } catch (cause) { setError(getErrorMessage(cause)); } finally { setSaving(false); } };
return ( <Switch> <Match when={repoQuery.isLoading}> <div class={cardStyles('p-4')}> <LoadingState label="loading repository..." /> </div> </Match> <Match when={repoQuery.error}> <div class={cardStyles('p-4')}> <ErrorState message={getErrorMessage(repoQuery.error)} /> </div> </Match> <Match when={repoQuery.data}> {(repo) => ( <Show when={auth.currentDid()} fallback={ <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded p-4 relative flex gap-2 items-center dark:text-white"> please log in to fork this repository. </div> } > <div class="grid grid-cols-12 dark:text-white"> <div class="col-span-full md:col-start-3 md:col-span-8 px-4 py-1 mb-2"> <h1 class="text-xl font-bold dark:text-white mb-1 flex items-center gap-2 flex-wrap"> <GitFork class="size-5 shrink-0" /> <span>fork</span> <span class="flex items-center gap-1 font-normal"> <Avatar did={repo().owner.did} size="size-5" /> <A href={`/${repo().owner.handle}`} class="font-medium"> {repo().owner.handle} </A> <span class="text-gray-400 dark:text-gray-500">/</span> <A href={`/${repo().owner.handle}/${repo().slug}`} class="font-semibold"> {repo().slug} </A> </span> </h1> </div>
<div class="col-span-full md:col-start-3 md:col-span-8 bg-white dark:bg-gray-800 drop-shadow-sm rounded overflow-hidden border border-gray-200 dark:border-gray-700"> <div class="flex items-center gap-3 p-3 md:px-5 border-b border-gray-100 dark:border-gray-700 text-gray-700 dark:text-gray-300"> <Info class="size-5 text-gray-500 dark:text-gray-400 shrink-0" /> <p class="text-sm"> a fork is your own copy of this repository. <br /> use it to work independently, then open a pull request back upstream. </p> </div>
<form onSubmit={handleSubmit} class="p-4 md:px-6"> {error() && <p class="text-red-500 dark:text-red-400 text-sm mb-3">{error()}</p>}
<div class="untangled-timeline-step untangled-timeline-step-1 untangled-fork-step"> <div class="untangled-timeline-circle"> <div class="untangled-timeline-circle-inner">1</div> </div>
<div class="flex-1 pb-6 pt-1"> <h2 class="untangled-fork-step-title text-lg font-medium dark:text-white">details</h2> <div class="text-sm text-gray-500 dark:text-gray-400 mb-3">basic repository information.</div>
<div class="space-y-3 mt-3"> <div> <label for="fork-name" class="block text-sm font-bold dark:text-white mb-1"> REPOSITORY NAME </label> <div class="flex flex-col md:flex-row md:items-center w-full"> <div class="shrink-0 hidden md:flex items-center px-3 py-2 gap-1.5 text-sm text-gray-700 dark:text-gray-300 border border-r-0 border-gray-300 dark:border-gray-600 rounded-l bg-gray-50 dark:bg-gray-700 h-[38px]"> <Avatar did={auth.currentDid()!} size="size-5" /> <span>{viewerLabel()}</span> </div> <input type="text" id="fork-name" name="repo_name" value={name()} onInput={(event) => setName(event.currentTarget.value)} required class="flex-1 md:rounded-r md:rounded-l-none rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 px-3 py-2 text-sm text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 h-[38px]" placeholder="repository-name" /> </div> <p class="text-sm text-gray-500 dark:text-gray-400 mt-1"> choose a unique, descriptive name for your repository. use letters, numbers, and hyphens. </p> </div>
<div class="pt-2"> <label for="fork-description" class="block text-sm font-bold dark:text-white mb-1"> DESCRIPTION </label> <input type="text" id="fork-description" name="description" value={description()} onInput={(event) => setDescription(event.currentTarget.value)} maxlength="140" class="w-full rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 px-3 py-2 text-sm text-gray-900 dark:text-gray-100 focus:outline-none focus:ring-1 focus:ring-blue-500 focus:border-blue-500 h-[38px]" placeholder="a brief description of your project..." /> <p class="text-sm text-gray-500 dark:text-gray-400 mt-1"> optional. a short description to help others understand what your project does ({descriptionLength()}/140 characters). </p> </div> </div> </div> </div>
<div class="untangled-timeline-step untangled-timeline-step-2 untangled-fork-step"> <div class="untangled-timeline-circle"> <div class="untangled-timeline-circle-inner">2</div> </div>
<div class="flex-1 pt-1"> <h2 class="untangled-fork-step-title text-lg font-medium dark:text-white">knot selection</h2> <div class="text-sm text-gray-500 dark:text-gray-400 mb-3">repository settings and hosting.</div>
<div class="space-y-3 mt-3"> <div class="pt-2"> <label class="block text-sm font-bold dark:text-white mb-1"> SELECT A KNOT </label> <div class="w-full space-y-1 py-0"> <Show when={!knotsQuery.isLoading} fallback={<div class="text-sm text-gray-500 dark:text-gray-400">loading knots...</div>} > <Show when={knotsQuery.data && knotsQuery.data.length > 0} fallback={<p class="text-sm text-gray-500 dark:text-gray-400">no knots available.</p>} > <For each={knotsQuery.data}> {(knot) => ( <div class="flex items-center leading-tight"> <input type="radio" name="knot" value={knot} checked={selectedKnot() === knot} onChange={() => setSelectedKnot(knot)} class="mr-2 cursor-pointer" id={`fork-knot-${knot}`} required /> <label for={`fork-knot-${knot}`} class="dark:text-white lowercase cursor-pointer"> {knot} </label> </div> )} </For> </Show> </Show> </div> <p class="text-sm text-gray-500 dark:text-gray-400 mt-1"> a knot hosts repository data and handles git operations. you can also{' '} <A href="/settings/knots" class="underline"> register your own knot </A> . </p> </div> </div> </div> </div>
<div class="untangled-repo-form-submit flex justify-end"> <button type="submit" disabled={saving() || !selectedKnot()} class="btn-create flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed" > <Show when={saving()} fallback={<GitFork class="w-4 h-4" />}> <LoaderCircle class="w-4 h-4 animate-spin" /> </Show> fork repo </button> </div> </form> </div> </div> </Show> )} </Match> </Switch> );};132 unmodified linesExpand all1331341351361371371381391401411421431431441451451461471481491501501511521521531541551561 unmodified line15815916016116216216316416416516616616716816917019 unmodified lines19019119219319419419519619719821 unmodified lines22022122222322422422522622622722822822923023123212 unmodified lines2452462472482492492502512522532532542552562572 unmodified lines26026126226326426426526626726823 unmodified lines29229329429529629629729829930013 unmodified lines132 unmodified linesExpand all return ( <Show when={auth.currentDid()} fallback={ <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded p-6 relative flex gap-2 items-center dark:text-white"> <div class="bg-amber-50 dark:bg-amber-900 border border-amber-500 rounded p-4 relative flex gap-2 items-center dark:text-white"> please log in to create a new repository. </div> } > <div class="grid grid-cols-12 dark:text-white"> <div class="col-span-full md:col-start-3 md:col-span-8 px-6 py-2 mb-4"> <div class="col-span-full md:col-start-3 md:col-span-8 px-4 py-1 mb-2"> <h1 class="text-xl font-bold dark:text-white mb-1">create a new repository</h1> <p class="text-gray-600 dark:text-gray-400 mb-1"> <p class="text-gray-600 dark:text-gray-400"> repositories contain a project's files and version history. all repositories are publicly accessible. </p> </div>
<div class="col-span-full md:col-start-3 md:col-span-8 bg-white dark:bg-gray-800 drop-shadow-sm rounded p-6 md:px-10 border border-gray-200 dark:border-gray-700"> <div class="col-span-full md:col-start-3 md:col-span-8 bg-white dark:bg-gray-800 drop-shadow-sm rounded p-4 md:px-6 border border-gray-200 dark:border-gray-700"> <form onSubmit={handleSubmit}> {error() && <p class="text-red-500 dark:text-red-400 text-sm mb-4">{error()}</p>} {error() && <p class="text-red-500 dark:text-red-400 text-sm mb-3">{error()}</p>}
{/* Step 1 */} <div class="untangled-timeline-step untangled-timeline-step-1"> <div class="untangled-timeline-circle">1 unmodified line 1 </div> </div>
<div class="flex-1 pb-12"> <div class="flex-1 pb-6 pt-1"> <h2 class="text-lg font-medium dark:text-white">general</h2> <div class="text-sm text-gray-500 dark:text-gray-400 mb-4">basic repository information.</div> <div class="text-sm text-gray-500 dark:text-gray-400 mb-3">basic repository information.</div>
<div class="space-y-4"> <div class="space-y-3"> {/* Repository Name */} <div> <label class="block text-sm font-bold dark:text-white mb-1"> REPOSITORY NAME19 unmodified lines </p> </div>
{/* Description */} <div> <div class="pt-2"> <label for="description" class="block text-sm font-bold dark:text-white mb-1"> DESCRIPTION </label> <input21 unmodified lines 2 </div> </div>
<div class="flex-1"> <div class="flex-1 pt-1"> <h2 class="text-lg font-medium dark:text-white">configuration</h2> <div class="text-sm text-gray-500 dark:text-gray-400 mb-4">repository settings and hosting.</div> <div class="text-sm text-gray-500 dark:text-gray-400 mb-3">repository settings and hosting.</div>
<div class="space-y-4"> <div class="space-y-3"> {/* Default Branch */} <div> <label for="branch" class="block text-sm font-bold dark:text-white mb-1"> DEFAULT BRANCH12 unmodified lines </p> </div>
{/* Knot Selection */} <div> <div class="pt-2"> <label class="block text-sm font-bold dark:text-white mb-1"> SELECT A KNOT </label> <div class="w-full space-y-2 py-1"> <div class="w-full space-y-1 py-0"> <Show when={!knotsQuery.isLoading} fallback={<div class="text-sm text-gray-500 dark:text-gray-400">loading knots...</div>} >2 unmodified lines fallback={<p class="dark:text-white">no knots available.</p>} > <For each={knotsQuery.data}> {(knot) => ( <div class="flex items-center"> <div class="flex items-center leading-tight"> <input type="radio" name="domain" value={knot}23 unmodified lines </div> </div> </div>
<div class="mt-8 flex justify-end"> <div class="untangled-repo-form-submit flex justify-end"> <button type="submit" disabled={saving() || !selectedKnot()} class="btn-create flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed"13 unmodified lines340 unmodified linesExpand all341342343344345346347348345346347348349350353351352353354355146 unmodified linesExpand all340 unmodified linesExpand all </span> </Show> </div> <div class="untangled-repo-action"> <a href={`https://tangled.org/${repo().owner.handle}/${repo().slug}/fork`} target="_blank" rel="noreferrer" <A href={`/${repo().owner.handle}/${repo().slug}/fork`} class="untangled-repo-action-main" > <GitFork class="size-4" /> <span>fork</span> </a> </A> <Show when={forkCountQuery.isLoading} fallback={ <a146 unmodified linesExpand all