diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-05 15:28:33 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-05 15:28:33 +0000 |
| commit | 96203000f81a46976834971dd26e1a79465e6303 (patch) | |
| tree | 1a95e1260b13ff50ad564e09ecc7f3e88b3d6d21 /src/git/handlers.rs | |
| parent | b29c0362bfb881febf9848e40023ac588d1e9aa7 (diff) | |
sync PR refs to all relivant repos
Diffstat (limited to 'src/git/handlers.rs')
| -rw-r--r-- | src/git/handlers.rs | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs index 23a15ba..2325106 100644 --- a/src/git/handlers.rs +++ b/src/git/handlers.rs | |||
| @@ -16,7 +16,7 @@ use super::subprocess::GitSubprocess; | |||
| 16 | use super::try_set_head_if_available; | 16 | use super::try_set_head_if_available; |
| 17 | 17 | ||
| 18 | use crate::git::authorization::{authorize_push, fetch_repository_data, parse_pushed_refs}; | 18 | use crate::git::authorization::{authorize_push, fetch_repository_data, parse_pushed_refs}; |
| 19 | use crate::git::sync::{sync_pr_refs_to_owner_repos, sync_to_owner_repos}; | 19 | use crate::git::sync::{sync_pr_refs_to_tagged_owner_repos, sync_to_owner_repos}; |
| 20 | use crate::nostr::builder::SharedDatabase; | 20 | use crate::nostr::builder::SharedDatabase; |
| 21 | use crate::nostr::events::{KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_STATE}; | 21 | use crate::nostr::events::{KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_STATE}; |
| 22 | use crate::purgatory::Purgatory; | 22 | use crate::purgatory::Purgatory; |
| @@ -389,36 +389,53 @@ pub async fn handle_receive_pack( | |||
| 389 | let pr_refs: Vec<(String, String)> = pushed_refs | 389 | let pr_refs: Vec<(String, String)> = pushed_refs |
| 390 | .iter() | 390 | .iter() |
| 391 | .filter_map(|(_, new_oid, ref_name)| { | 391 | .filter_map(|(_, new_oid, ref_name)| { |
| 392 | ref_name.strip_prefix("refs/nostr/").map(|event_id| { | 392 | ref_name |
| 393 | (event_id.to_string(), new_oid.clone()) | 393 | .strip_prefix("refs/nostr/") |
| 394 | }) | 394 | .map(|event_id| (event_id.to_string(), new_oid.clone())) |
| 395 | }) | 395 | }) |
| 396 | .collect(); | 396 | .collect(); |
| 397 | 397 | ||
| 398 | if !pr_refs.is_empty() { | 398 | if !pr_refs.is_empty() { |
| 399 | // Extract PR events from purgatory_events (filter for KIND_PR and KIND_PR_UPDATE) | ||
| 400 | let purgatory_pr_events: Vec<_> = auth_result | ||
| 401 | .purgatory_events | ||
| 402 | .iter() | ||
| 403 | .filter(|e| e.kind == Kind::from(KIND_PR) || e.kind == Kind::from(KIND_PR_UPDATE)) | ||
| 404 | .cloned() | ||
| 405 | .collect(); | ||
| 406 | |||
| 399 | match fetch_repository_data(&database, identifier).await { | 407 | match fetch_repository_data(&database, identifier).await { |
| 400 | Ok(db_repo_data) => { | 408 | Ok(db_repo_data) => { |
| 401 | let git_data_path_buf = std::path::PathBuf::from(git_data_path); | 409 | let git_data_path_buf = std::path::PathBuf::from(git_data_path); |
| 402 | let pr_sync_result = sync_pr_refs_to_owner_repos( | ||
| 403 | &repo_path, | ||
| 404 | &pr_refs, | ||
| 405 | &db_repo_data, | ||
| 406 | &git_data_path_buf, | ||
| 407 | owner_pubkey, | ||
| 408 | ); | ||
| 409 | 410 | ||
| 410 | if pr_sync_result.repos_synced > 0 { | 411 | // sync to owner repos and repos of other owners that list them as maintainers |
| 411 | info!( | 412 | // This uses the `a` tags from PR events to find tagged owner repos |
| 412 | "Synced {} PR refs to {} other owner repositories for {}", | 413 | if !purgatory_pr_events.is_empty() { |
| 413 | pr_sync_result.refs_created, | 414 | let tagged_sync_result = sync_pr_refs_to_tagged_owner_repos( |
| 414 | pr_sync_result.repos_synced, | 415 | &repo_path, |
| 415 | identifier | 416 | &pr_refs, |
| 417 | &purgatory_pr_events, | ||
| 418 | &db_repo_data, | ||
| 419 | &git_data_path_buf, | ||
| 420 | owner_pubkey, | ||
| 416 | ); | 421 | ); |
| 417 | } | ||
| 418 | 422 | ||
| 419 | if !pr_sync_result.errors.is_empty() { | 423 | if tagged_sync_result.repos_synced > 0 { |
| 420 | for (repo, error) in &pr_sync_result.errors { | 424 | info!( |
| 421 | warn!("Error syncing PR ref to {}: {}", repo, error); | 425 | "Synced {} PR refs to {} other owner repositories for {} (via tagged owners)", |
| 426 | tagged_sync_result.refs_created, | ||
| 427 | tagged_sync_result.repos_synced, | ||
| 428 | identifier | ||
| 429 | ); | ||
| 430 | } | ||
| 431 | |||
| 432 | if !tagged_sync_result.errors.is_empty() { | ||
| 433 | for (repo, error) in &tagged_sync_result.errors { | ||
| 434 | warn!( | ||
| 435 | "Error syncing PR ref to {} (via tagged owner): {}", | ||
| 436 | repo, error | ||
| 437 | ); | ||
| 438 | } | ||
| 422 | } | 439 | } |
| 423 | } | 440 | } |
| 424 | } | 441 | } |