upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git/handlers.rs')
-rw-r--r--src/git/handlers.rs38
1 files changed, 36 insertions, 2 deletions
diff --git a/src/git/handlers.rs b/src/git/handlers.rs
index 2930852..e86d2a3 100644
--- a/src/git/handlers.rs
+++ b/src/git/handlers.rs
@@ -15,7 +15,8 @@ use super::protocol::{GitService, PktLine};
15use super::subprocess::GitSubprocess; 15use super::subprocess::GitSubprocess;
16use super::try_set_head_if_available; 16use super::try_set_head_if_available;
17 17
18use crate::git::authorization::authorize_push; 18use crate::git::authorization::{authorize_push, fetch_repository_data};
19use crate::git::sync::sync_to_owner_repos;
19use crate::nostr::builder::SharedDatabase; 20use crate::nostr::builder::SharedDatabase;
20use crate::nostr::events::{KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_STATE}; 21use crate::nostr::events::{KIND_PR, KIND_PR_UPDATE, KIND_REPOSITORY_STATE};
21use crate::purgatory::Purgatory; 22use crate::purgatory::Purgatory;
@@ -180,6 +181,7 @@ pub async fn handle_upload_pack(
180/// * `database` - Database reference for authorization queries 181/// * `database` - Database reference for authorization queries
181/// * `identifier` - The repository identifier (d tag) for authorization lookup 182/// * `identifier` - The repository identifier (d tag) for authorization lookup
182/// * `owner_pubkey` - The owner's public key (hex) from the URL path, scoping authorization 183/// * `owner_pubkey` - The owner's public key (hex) from the URL path, scoping authorization
184/// * `git_data_path` - Base path for git repositories (for syncing to other owner repos)
183pub async fn handle_receive_pack( 185pub async fn handle_receive_pack(
184 repo_path: PathBuf, 186 repo_path: PathBuf,
185 request_body: Bytes, 187 request_body: Bytes,
@@ -188,6 +190,7 @@ pub async fn handle_receive_pack(
188 identifier: &str, 190 identifier: &str,
189 owner_pubkey: &str, 191 owner_pubkey: &str,
190 purgatory: Arc<Purgatory>, 192 purgatory: Arc<Purgatory>,
193 git_data_path: &str,
191) -> Result<Response<Full<Bytes>>, GitError> { 194) -> Result<Response<Full<Bytes>>, GitError> {
192 debug!("Handling receive-pack for {:?}", repo_path); 195 debug!("Handling receive-pack for {:?}", repo_path);
193 196
@@ -347,7 +350,38 @@ pub async fn handle_receive_pack(
347 } 350 }
348 351
349 // TODO figure out what atomic pushes look like in GRASP (we cant accepted differnte state events changing different branches at the same time) 352 // TODO figure out what atomic pushes look like in GRASP (we cant accepted differnte state events changing different branches at the same time)
350 // TODO sync git data to other repos that these events authorise. 353
354 // Sync git data to other owner repositories that authorize the same state event
355 // This ensures all owners who share maintainers get the same git data
356 if let Some(ref state) = auth_result.state {
357 // Fetch repository data for sync
358 match fetch_repository_data(&database, identifier).await {
359 Ok(db_repo_data) => {
360 let git_data_path_buf = std::path::PathBuf::from(git_data_path);
361 let sync_result =
362 sync_to_owner_repos(&repo_path, state, &db_repo_data, &git_data_path_buf);
363
364 if sync_result.repos_synced > 0 {
365 info!(
366 "Synced git data to {} other owner repositories for {}",
367 sync_result.repos_synced, identifier
368 );
369 }
370
371 if !sync_result.errors.is_empty() {
372 for (repo, error) in &sync_result.errors {
373 warn!("Error syncing to {}: {}", repo, error);
374 }
375 }
376 }
377 Err(e) => {
378 warn!(
379 "Failed to fetch repository data for sync after push to {}: {}",
380 identifier, e
381 );
382 }
383 }
384 }
351 385
352 Ok(Response::builder() 386 Ok(Response::builder()
353 .status(StatusCode::OK) 387 .status(StatusCode::OK)