diff options
Diffstat (limited to 'src/sub_commands/send.rs')
| -rw-r--r-- | src/sub_commands/send.rs | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 410e119..a289def 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use std::{str::FromStr, time::Duration}; | 1 | use std::{path::Path, str::FromStr, time::Duration}; |
| 2 | 2 | ||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use console::Style; | 4 | use console::Style; |
| @@ -19,10 +19,12 @@ use crate::{ | |||
| 19 | cli_interactor::{ | 19 | cli_interactor::{ |
| 20 | Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms, PromptMultiChoiceParms, | 20 | Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms, PromptMultiChoiceParms, |
| 21 | }, | 21 | }, |
| 22 | client::{sign_event, Connect}, | 22 | client::{ |
| 23 | fetching_with_report, get_events_from_cache, get_repo_ref_from_cache, sign_event, Connect, | ||
| 24 | }, | ||
| 23 | git::{Repo, RepoActions}, | 25 | git::{Repo, RepoActions}, |
| 24 | login, | 26 | login, |
| 25 | repo_ref::{self, RepoRef, REPO_REF_KIND}, | 27 | repo_ref::{get_repo_coordinates, RepoRef, REPO_REF_KIND}, |
| 26 | Cli, | 28 | Cli, |
| 27 | }; | 29 | }; |
| 28 | 30 | ||
| @@ -49,6 +51,7 @@ pub struct SubCommandArgs { | |||
| 49 | #[allow(clippy::too_many_lines)] | 51 | #[allow(clippy::too_many_lines)] |
| 50 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | 52 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { |
| 51 | let git_repo = Repo::discover().context("cannot find a git repository")?; | 53 | let git_repo = Repo::discover().context("cannot find a git repository")?; |
| 54 | let git_repo_path = git_repo.get_path()?; | ||
| 52 | 55 | ||
| 53 | let (main_branch_name, main_tip) = git_repo | 56 | let (main_branch_name, main_tip) = git_repo |
| 54 | .get_main_or_master_branch() | 57 | .get_main_or_master_branch() |
| @@ -59,13 +62,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 59 | #[cfg(test)] | 62 | #[cfg(test)] |
| 60 | let mut client = <MockConnect as std::default::Default>::default(); | 63 | let mut client = <MockConnect as std::default::Default>::default(); |
| 61 | 64 | ||
| 62 | let (root_proposal_id, mention_tags) = get_root_proposal_id_and_mentions_from_in_reply_to( | 65 | let repo_coordinates = get_repo_coordinates(&git_repo, &client).await?; |
| 63 | &client, | 66 | |
| 64 | // TODO: user repo relays when when event cache is in place | 67 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; |
| 65 | client.get_fallback_relays(), | 68 | |
| 66 | &args.in_reply_to, | 69 | let (root_proposal_id, mention_tags) = |
| 67 | ) | 70 | get_root_proposal_id_and_mentions_from_in_reply_to(git_repo.get_path()?, &args.in_reply_to) |
| 68 | .await?; | 71 | .await?; |
| 69 | 72 | ||
| 70 | if let Some(root_ref) = args.in_reply_to.first() { | 73 | if let Some(root_ref) = args.in_reply_to.first() { |
| 71 | if root_proposal_id.is_some() { | 74 | if root_proposal_id.is_some() { |
| @@ -191,17 +194,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 191 | 194 | ||
| 192 | client.set_signer(signer.clone()).await; | 195 | client.set_signer(signer.clone()).await; |
| 193 | 196 | ||
| 194 | let repo_ref = repo_ref::fetch( | 197 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 195 | &git_repo, | ||
| 196 | git_repo | ||
| 197 | .get_root_commit() | ||
| 198 | .context("failed to get root commit of the repository")? | ||
| 199 | .to_string(), | ||
| 200 | &client, | ||
| 201 | user_ref.relays.write(), | ||
| 202 | true, | ||
| 203 | ) | ||
| 204 | .await?; | ||
| 205 | 198 | ||
| 206 | // oldest first | 199 | // oldest first |
| 207 | commits.reverse(); | 200 | commits.reverse(); |
| @@ -520,9 +513,7 @@ fn summarise_commit_for_selection(git_repo: &Repo, commit: &Sha1Hash) -> Result< | |||
| 520 | } | 513 | } |
| 521 | 514 | ||
| 522 | async fn get_root_proposal_id_and_mentions_from_in_reply_to( | 515 | async fn get_root_proposal_id_and_mentions_from_in_reply_to( |
| 523 | #[cfg(test)] client: &crate::client::MockConnect, | 516 | git_repo_path: &Path, |
| 524 | #[cfg(not(test))] client: &Client, | ||
| 525 | repo_relays: &[String], | ||
| 526 | in_reply_to: &[String], | 517 | in_reply_to: &[String], |
| 527 | ) -> Result<(Option<String>, Vec<nostr::Tag>)> { | 518 | ) -> Result<(Option<String>, Vec<nostr::Tag>)> { |
| 528 | let root_proposal_id = if let Some(first) = in_reply_to.first() { | 519 | let root_proposal_id = if let Some(first) = in_reply_to.first() { |
| @@ -535,13 +526,10 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 535 | marker: _, | 526 | marker: _, |
| 536 | public_key: _, | 527 | public_key: _, |
| 537 | }) => { | 528 | }) => { |
| 538 | let events = client | 529 | let events = |
| 539 | .get_events( | 530 | get_events_from_cache(git_repo_path, vec![nostr::Filter::new().id(*event_id)]) |
| 540 | repo_relays.to_vec(), | 531 | .await?; |
| 541 | vec![nostr::Filter::new().id(*event_id)], | 532 | |
| 542 | ) | ||
| 543 | .await | ||
| 544 | .context("whilst getting events specified in --in-reply-to")?; | ||
| 545 | if let Some(first) = events.iter().find(|e| e.id.eq(event_id)) { | 533 | if let Some(first) = events.iter().find(|e| e.id.eq(event_id)) { |
| 546 | if event_is_patch_set_root(first) { | 534 | if event_is_patch_set_root(first) { |
| 547 | Some(event_id.to_string()) | 535 | Some(event_id.to_string()) |
| @@ -549,10 +537,7 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 549 | None | 537 | None |
| 550 | } | 538 | } |
| 551 | } else { | 539 | } else { |
| 552 | bail!( | 540 | None |
| 553 | "cannot find first event specified in --in-reply-to \"{}\"", | ||
| 554 | first, | ||
| 555 | ) | ||
| 556 | } | 541 | } |
| 557 | } | 542 | } |
| 558 | _ => None, | 543 | _ => None, |