From f7fc018ae2507adbd26907746834a914876cf635 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Dec 2025 07:31:33 -0600 Subject: [PATCH] Update existing repo announcements with current GRASP servers - When an existing NIP-34 repository announcement is found, extract all metadata (name, description, web URLs, t-tags, earliest commit) - Update the announcement with current GRASP server clone URLs and relays from config - Publish the updated event to keep repository announcements in sync with GRASP configuration - Remove invalid onProjectDeleted prop from ProjectDetailsDialog usage (prop was removed in previous refactor) --- .../git-sync/steps/ConfigureRepoStep.tsx | 58 +++++++++++++++++-- src/pages/ProjectView.tsx | 2 - 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/components/git-sync/steps/ConfigureRepoStep.tsx b/src/components/git-sync/steps/ConfigureRepoStep.tsx index 7545b7c2..8b58d29b 100644 --- a/src/components/git-sync/steps/ConfigureRepoStep.tsx +++ b/src/components/git-sync/steps/ConfigureRepoStep.tsx @@ -60,12 +60,60 @@ export function ConfigureRepoStep({ let repoEvent: NostrEvent; if (existingRepos.length > 0) { - // Use existing repo announcement - repoEvent = existingRepos[0]; + // Use existing repo announcement as template and update with current GRASP servers + const existingEvent = existingRepos[0]; - // Republish the event - // TODO: use this event as a template, and "fix" it, signing and publishing a new event - await nostr.event(repoEvent); + // Convert user's GRASP servers to clone URLs and relay URLs + const npub = nip19.npubEncode(user.pubkey); + const cloneUrls = new Set(); + const relays = new Set(); + + for (const graspRelay of config.graspMetadata.relays) { + try { + const relayUrl = new URL(graspRelay.url); + relays.add(relayUrl.href); + + const cloneUrl = new URL(`/${npub}/${projectId}.git`, `https://${relayUrl.host}`); + + cloneUrls.add(cloneUrl.href); + } catch (err) { + console.warn(`Failed to parse Nostr git relay URL: ${graspRelay.url}`, err); + } + } + + // Validate that we have at least one clone URL and relay + if (cloneUrls.size === 0 || relays.size === 0) { + throw new Error('No Nostr git servers configured. Please configure Nostr git servers in Settings > Nostr.'); + } + + // Extract existing data from the event + const name = existingEvent.tags.find(([tagName]) => tagName === 'name')?.[1]; + const description = existingEvent.tags.find(([tagName]) => tagName === 'description')?.[1]; + const webTag = existingEvent.tags.find(([tagName]) => tagName === 'web'); + const webUrls = webTag ? webTag.slice(1) : undefined; + const tTags = existingEvent.tags + .filter(([tagName]) => tagName === 't') + .map(([, value]) => value); + const eucTag = existingEvent.tags.find(([tagName, , marker]) => tagName === 'r' && marker === 'euc'); + const earliestCommit = eucTag?.[1]; + + // Create updated repository announcement event with new clone URLs and relays + const eventTemplate = createRepositoryAnnouncementEvent({ + repoId: projectId, + name, + description, + webUrls, + cloneUrls: [...cloneUrls], + relays: [...relays], + tTags: tTags.length > 0 ? tTags : undefined, + earliestCommit, + }); + + // Publish the updated event + repoEvent = await publishEvent(eventTemplate); + + // Wait 5 seconds for Nostr git servers to update + await new Promise(resolve => setTimeout(resolve, 5000)); } else { // Create and publish new NIP-34 repository announcement diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index 8d01e9e7..bb122fbe 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -443,7 +443,6 @@ export function ProjectView() { project={project} open={isProjectDetailsOpen} onOpenChange={setIsProjectDetailsOpen} - onProjectDeleted={handleProjectDeleted} />