diff options
Diffstat (limited to 'src/bin/git_remote_nostr/push.rs')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 3967699..4552b91 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -450,18 +450,38 @@ async fn generate_patches_or_pr_event_or_pr_updates( | |||
| 450 | signer: &Arc<dyn NostrSigner>, | 450 | signer: &Arc<dyn NostrSigner>, |
| 451 | term: &Term, | 451 | term: &Term, |
| 452 | ) -> Result<Vec<Event>> { | 452 | ) -> Result<Vec<Event>> { |
| 453 | let mut events: Vec<Event> = vec![]; | ||
| 454 | let parent_is_pr = root_proposal.is_some_and(|proposal| proposal.kind.eq(&KIND_PULL_REQUEST)); | 453 | let parent_is_pr = root_proposal.is_some_and(|proposal| proposal.kind.eq(&KIND_PULL_REQUEST)); |
| 455 | let use_pr = parent_is_pr || git_repo.are_commits_too_big_for_patches(ahead); | 454 | let use_pr = parent_is_pr || git_repo.are_commits_too_big_for_patches(ahead); |
| 456 | 455 | ||
| 457 | if use_pr { | 456 | if use_pr { |
| 458 | for event in push_refs_and_generate_pr_or_pr_update_event( | 457 | let repo_grasps = repo_ref.grasp_servers(); |
| 458 | let repo_grasp_clone_urls: Vec<String> = repo_ref | ||
| 459 | .git_server | ||
| 460 | .iter() | ||
| 461 | .filter(|s| is_grasp_server(s, &repo_grasps)) | ||
| 462 | .cloned() | ||
| 463 | .collect(); | ||
| 464 | |||
| 465 | if repo_grasp_clone_urls.is_empty() { | ||
| 466 | // TODO get grasp_default_set servers that aren't in repo_grasps | ||
| 467 | // cycle through until one succeeds TODO create | ||
| 468 | // personal-fork announcement with grasp servers and | ||
| 469 | // push, after a few seconds push ref/nostr/eventid. if | ||
| 470 | // one success break out of for loop and continue | ||
| 471 | |||
| 472 | bail!( | ||
| 473 | "The repository doesnt list a grasp server which would otherwise be used to submit your proposal as nostr Pull Request. Soon ngit will support pushing your changes to a different git / grasp git server." | ||
| 474 | ); | ||
| 475 | } | ||
| 476 | |||
| 477 | if let (Some(events), _) = push_refs_and_generate_pr_or_pr_update_event( | ||
| 459 | git_repo, | 478 | git_repo, |
| 460 | repo_ref, | 479 | repo_ref, |
| 461 | ahead.first().context("no commits to push")?, | 480 | ahead.first().context("no commits to push")?, |
| 462 | user_ref, | 481 | user_ref, |
| 463 | root_proposal, | 482 | root_proposal, |
| 464 | &None, | 483 | &None, |
| 484 | &repo_grasp_clone_urls, | ||
| 465 | signer, | 485 | signer, |
| 466 | term, | 486 | term, |
| 467 | ) | 487 | ) |
| @@ -471,12 +491,17 @@ async fn generate_patches_or_pr_event_or_pr_updates( | |||
| 471 | } else { | 491 | } else { |
| 472 | "a commit in your proposal is too big for a nostr patch so we tried to create it as a nostr PR instead. Unfortunately this failed." | 492 | "a commit in your proposal is too big for a nostr patch so we tried to create it as a nostr PR instead. Unfortunately this failed." |
| 473 | } | 493 | } |
| 474 | )? | 494 | )? { |
| 475 | { | 495 | Ok(events) |
| 476 | events.push(event); | 496 | } else { |
| 497 | bail!( | ||
| 498 | "a commit in your proposal is too big for a nostr patch. tried to use submit as a nostr Pull Request but could not find a grasp server that would accept your changes" | ||
| 499 | ); | ||
| 500 | // TODO suggest `ngit send` where user could specify their own clone | ||
| 501 | // url to push to once that feature is added | ||
| 477 | } | 502 | } |
| 478 | } else { | 503 | } else { |
| 479 | for patch in generate_cover_letter_and_patch_events( | 504 | generate_cover_letter_and_patch_events( |
| 480 | None, | 505 | None, |
| 481 | git_repo, | 506 | git_repo, |
| 482 | ahead, | 507 | ahead, |
| @@ -485,13 +510,8 @@ async fn generate_patches_or_pr_event_or_pr_updates( | |||
| 485 | &root_proposal.map(|proposal| proposal.id.to_string()), | 510 | &root_proposal.map(|proposal| proposal.id.to_string()), |
| 486 | &[], | 511 | &[], |
| 487 | ) | 512 | ) |
| 488 | .await? | 513 | .await |
| 489 | { | ||
| 490 | events.push(patch); | ||
| 491 | } | ||
| 492 | } | 514 | } |
| 493 | |||
| 494 | Ok(events) | ||
| 495 | } | 515 | } |
| 496 | 516 | ||
| 497 | type HashMapUrlRefspecs = HashMap<String, Vec<String>>; | 517 | type HashMapUrlRefspecs = HashMap<String, Vec<String>>; |