From e72edbae86affcb9fc0429bd197639bf438ffb6c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 7 Jan 2026 12:24:42 +0000 Subject: Add unified process_newly_available_git_data function Implement the unified function that handles all post-git-data-available processing, regardless of how data arrived (git push or purgatory sync). This function: - Discovers satisfiable events from purgatory (state and PR events) - Syncs OIDs to authorized owner repos - Aligns refs and sets HEAD - Saves events to database - Notifies WebSocket subscribers - Removes from purgatory New additions: - ProcessResult struct for tracking processing outcomes - process_newly_available_git_data async function in src/git/sync.rs - Helper functions: extract_identifier_from_repo_path, extract_identifier_from_pr_event - Purgatory::find_prs_for_identifier method for PR event discovery - Unit tests for all helper functions Also fixes: - Simplified extract_domain to avoid url crate dependency - Removed unused imports in sync/loop.rs --- src/purgatory/mod.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/purgatory/mod.rs') diff --git a/src/purgatory/mod.rs b/src/purgatory/mod.rs index fcb812b..11fe41f 100644 --- a/src/purgatory/mod.rs +++ b/src/purgatory/mod.rs @@ -365,6 +365,33 @@ impl Purgatory { }) } + /// Find all PR events for a specific repository identifier. + /// + /// PR events reference repositories via `a` tags with format `30617::`. + /// This function scans all PR entries and returns those that reference the given identifier. + /// + /// Note: This is a linear scan since PR events are indexed by event_id, not by identifier. + /// For repositories with many PR events, this could be optimized with a secondary index. + /// + /// # Arguments + /// * `identifier` - The repository identifier to search for + /// + /// # Returns + /// Vector of PR purgatory entries that reference this identifier + pub fn find_prs_for_identifier(&self, identifier: &str) -> Vec { + self.pr_events + .iter() + .filter(|entry| { + if let Some(ref event) = entry.value().event { + Self::event_references_identifier(event, identifier) + } else { + false + } + }) + .map(|entry| entry.value().clone()) + .collect() + } + /// Remove a state event from purgatory. /// /// Removes all entries for the given identifier. -- cgit v1.2.3