From d76003b629a4a03dba23a8a1c41da6e4ac4c30cf Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 18 Feb 2026 17:12:17 +0000 Subject: feat: upgrade repo to Full sync and trigger PR event subscription after announcement promotion When git data arrives for a purgatory announcement and promotes it to the database, the relay now: 1. Upgrades the announcement's sync level in RepoSyncIndex from StateOnly to Full (git/sync.rs: process_purgatory_announcements) 2. Sends AddFilters actions to SyncManager for all connected relays, using Full sync filters (Layer 2 #a/#A/#q) to subscribe to PR events (purgatory/sync/context.rs: RealSyncContext.process_newly_available_git_data) 3. For user-submitted purgatory announcements, registers the repo in RepoSyncIndex with StateOnly level and sends AddFilters to SyncManager so it discovers and connects to relays listed in the announcement tags (nostr/builder.rs: handle_announcement AcceptPurgatory path) The RealSyncContext now accepts optional repo_sync_index and sync_action_tx parameters. main.rs wires these up from SyncManager. PolicyContext gains repo_sync_index and sync_action_tx fields for the write policy path. --- src/git/handlers.rs | 1 + src/git/sync.rs | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src/git') diff --git a/src/git/handlers.rs b/src/git/handlers.rs index 017eee4..129ca2c 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs @@ -307,6 +307,7 @@ pub async fn handle_receive_pack( Some(&relay), &purgatory, git_data_path_buf, + None, ) .await { diff --git a/src/git/sync.rs b/src/git/sync.rs index 4b35023..b3fa11a 100644 --- a/src/git/sync.rs +++ b/src/git/sync.rs @@ -44,6 +44,7 @@ use crate::git::{self, oid_exists}; use crate::nostr::builder::SharedDatabase; use crate::nostr::events::RepositoryState; use crate::purgatory::{can_apply_state, Purgatory}; +use crate::sync::{RepoSyncIndex, SyncLevel}; /// Result of processing newly available git data. /// @@ -809,6 +810,7 @@ pub fn extract_identifier_from_pr_event(event: &Event) -> Option { /// * `local_relay` - Local relay for notifying WebSocket subscribers (optional) /// * `purgatory` - Purgatory instance to check for satisfiable events /// * `git_data_path` - Base path for git repositories +/// * `repo_sync_index` - Optional repo sync index for upgrading sync level on promotion /// /// # Returns /// A `ProcessResult` describing what was processed @@ -819,6 +821,7 @@ pub async fn process_newly_available_git_data( local_relay: Option<&nostr_relay_builder::LocalRelay>, purgatory: &Purgatory, git_data_path: &Path, + repo_sync_index: Option, ) -> anyhow::Result { let mut result = ProcessResult::default(); @@ -848,6 +851,7 @@ pub async fn process_newly_available_git_data( local_relay, purgatory, git_data_path, + repo_sync_index.as_ref(), ) .await; result.merge(announcement_result); @@ -1284,6 +1288,7 @@ async fn process_purgatory_announcements( local_relay: Option<&nostr_relay_builder::LocalRelay>, purgatory: &Purgatory, git_data_path: &Path, + repo_sync_index: Option<&RepoSyncIndex>, ) -> ProcessResult { let mut result = ProcessResult::default(); @@ -1338,6 +1343,22 @@ async fn process_purgatory_announcements( } } + // Upgrade sync level to Full in repo_sync_index + if let Some(index) = repo_sync_index { + let mut index = index.write().await; + // Use hex pubkey format to match how repo_sync_index keys are built + // (sync/mod.rs uses event.pubkey which is hex, not bech32) + let repo_id = format!("30617:{}:{}", owner.to_hex(), identifier); + if let Some(entry) = index.get_mut(&repo_id) { + entry.sync_level = SyncLevel::Full; + debug!( + identifier = %identifier, + repo_id = %repo_id, + "Upgraded sync level to Full after announcement promotion" + ); + } + } + result.announcements_released += 1; } Err(e) => { -- cgit v1.2.3