diff options
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 44 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/send.rs | 64 |
2 files changed, 81 insertions, 27 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>>; |
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index 0aefb03..69ad1e6 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs | |||
| @@ -1,11 +1,13 @@ | |||
| 1 | use std::path::Path; | 1 | use std::{path::Path, str::FromStr}; |
| 2 | 2 | ||
| 3 | use anyhow::{Context, Result, bail}; | 3 | use anyhow::{Context, Result, bail}; |
| 4 | use console::Style; | 4 | use console::Style; |
| 5 | use ngit::{ | 5 | use ngit::{ |
| 6 | client::{Params, send_events}, | 6 | client::{Params, send_events}, |
| 7 | git::nostr_url::CloneUrl, | ||
| 7 | git_events::{EventRefType, KIND_PULL_REQUEST, generate_cover_letter_and_patch_events}, | 8 | git_events::{EventRefType, KIND_PULL_REQUEST, generate_cover_letter_and_patch_events}, |
| 8 | push::push_refs_and_generate_pr_or_pr_update_event, | 9 | push::push_refs_and_generate_pr_or_pr_update_event, |
| 10 | repo_ref::is_grasp_server, | ||
| 9 | utils::proposal_tip_is_pr_or_pr_update, | 11 | utils::proposal_tip_is_pr_or_pr_update, |
| 10 | }; | 12 | }; |
| 11 | use nostr::{ToBech32, event::Event, nips::nip19::Nip19Event}; | 13 | use nostr::{ToBech32, event::Event, nips::nip19::Nip19Event}; |
| @@ -192,20 +194,52 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re | |||
| 192 | commits.reverse(); | 194 | commits.reverse(); |
| 193 | 195 | ||
| 194 | let events = if as_pr { | 196 | let events = if as_pr { |
| 195 | push_refs_and_generate_pr_or_pr_update_event( | 197 | let repo_grasps = repo_ref.grasp_servers(); |
| 196 | &git_repo, | 198 | let repo_grasp_clone_urls: Vec<String> = repo_ref |
| 197 | &repo_ref, | 199 | .git_server |
| 198 | commits.last().context("no commits")?, | 200 | .iter() |
| 199 | &user_ref, | 201 | .filter(|s| is_grasp_server(s, &repo_grasps)) |
| 200 | root_proposal.as_ref(), | 202 | .cloned() |
| 201 | &cover_letter_title_description, | 203 | .collect(); |
| 202 | &signer, | 204 | if repo_grasp_clone_urls.is_empty() { |
| 203 | &console::Term::stdout(), | 205 | println!( |
| 204 | ) | 206 | "The repository doesn't list a grasp server which would otherwise be used to submit your proposal as nostr Pull Request." |
| 205 | .await? | 207 | ); |
| 206 | 208 | } | |
| 207 | // TODO | 209 | let mut to_try = repo_grasp_clone_urls.clone(); |
| 208 | // - allow specifying clone url and ref | 210 | let mut tried = vec![]; |
| 211 | loop { | ||
| 212 | let (events, _server_responses) = push_refs_and_generate_pr_or_pr_update_event( | ||
| 213 | &git_repo, | ||
| 214 | &repo_ref, | ||
| 215 | commits.last().context("no commits")?, | ||
| 216 | &user_ref, | ||
| 217 | root_proposal.as_ref(), | ||
| 218 | &cover_letter_title_description, | ||
| 219 | &repo_grasp_clone_urls, | ||
| 220 | &signer, | ||
| 221 | &console::Term::stdout(), | ||
| 222 | ) | ||
| 223 | .await?; | ||
| 224 | for url in to_try { | ||
| 225 | tried.push(url); | ||
| 226 | } | ||
| 227 | to_try = vec![]; | ||
| 228 | if let Some(events) = events { | ||
| 229 | break events; | ||
| 230 | } | ||
| 231 | let clone_url = Interactor::default() | ||
| 232 | .input( | ||
| 233 | PromptInputParms::default().with_prompt("git repo url with write permission"), | ||
| 234 | )? | ||
| 235 | .clone(); | ||
| 236 | if CloneUrl::from_str(&clone_url).is_ok() { | ||
| 237 | to_try.push(clone_url); | ||
| 238 | // TODO customise ref to push | ||
| 239 | } else { | ||
| 240 | println!("invalid clone url"); | ||
| 241 | } | ||
| 242 | } | ||
| 209 | } else { | 243 | } else { |
| 210 | let events = generate_cover_letter_and_patch_events( | 244 | let events = generate_cover_letter_and_patch_events( |
| 211 | cover_letter_title_description.clone(), | 245 | cover_letter_title_description.clone(), |