From 83448a99aaf18c7a045a081c5de0c22bc4a83de1 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 27 Nov 2024 17:08:25 +0000 Subject: chore: bump rust-nosrt v0.37.0 use RelayUrl in repo_ref which I had resisted as it mutates relay urls when printed to append a slash --- src/bin/git_remote_nostr/push.rs | 15 +++++----- src/bin/ngit/sub_commands/init.rs | 63 +++++++++++++++++++++++++++------------ src/bin/ngit/sub_commands/send.rs | 3 +- 3 files changed, 54 insertions(+), 27 deletions(-) (limited to 'src/bin') diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 381a45e..d8ba65a 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -961,9 +961,7 @@ async fn create_merge_status( public_keys.insert(revision.pubkey); } sign_event( - EventBuilder::new( - nostr::event::Kind::GitStatusApplied, - String::new(), + EventBuilder::new(nostr::event::Kind::GitStatusApplied, String::new()).tags( [ vec![ Tag::custom( @@ -972,23 +970,26 @@ async fn create_merge_status( ), Tag::from_standardized(nostr::TagStandard::Event { event_id: proposal.id, - relay_url: repo_ref.relays.first().map(nostr::UncheckedUrl::new), + relay_url: repo_ref.relays.first().cloned(), marker: Some(Marker::Root), public_key: None, + uppercase: false, }), Tag::from_standardized(nostr::TagStandard::Event { event_id: merged_patch, - relay_url: repo_ref.relays.first().map(nostr::UncheckedUrl::new), + relay_url: repo_ref.relays.first().cloned(), marker: Some(Marker::Mention), public_key: None, + uppercase: false, }), ], if let Some(revision) = revision { vec![Tag::from_standardized(nostr::TagStandard::Event { event_id: revision.id, - relay_url: repo_ref.relays.first().map(nostr::UncheckedUrl::new), + relay_url: repo_ref.relays.first().cloned(), marker: Some(Marker::Root), public_key: None, + uppercase: false, })] } else { vec![] @@ -1202,7 +1203,7 @@ impl BuildRepoState for RepoState { vec![value.clone()], )); } - let event = sign_event(EventBuilder::new(STATE_KIND, "", tags), signer).await?; + let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; Ok(RepoState { identifier, state, diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 2af6aef..0d3e344 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use anyhow::{Context, Result}; use ngit::cli_interactor::PromptConfirmParms; use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32}; -use nostr_sdk::Kind; +use nostr_sdk::{Kind, RelayUrl}; use crate::{ cli::{extract_signer_cli_arguments, Cli}, @@ -323,24 +323,45 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { // TODO: check if relays are free to post to so contributors can submit patches // TODO: recommend some reliable free ones - let relays: Vec = if args.relays.is_empty() { - Interactor::default() - .input( - PromptInputParms::default() - .with_prompt("relays") - .with_default(if let Ok(config) = &repo_config_result { - config.relays.clone().join(" ") - } else if let Some(repo_ref) = &repo_ref { - repo_ref.relays.clone().join(" ") - } else { - user_ref.relays.write().join(" ") - }), - )? - .split(' ') - .map(std::string::ToString::to_string) - .collect() - } else { - args.relays.clone() + let relays: Vec = { + let mut default = if let Ok(config) = &repo_config_result { + config.relays.clone().join(" ") + } else if let Some(repo_ref) = &repo_ref { + repo_ref + .relays + .iter() + .map(std::string::ToString::to_string) + .collect::>() + .join(" ") + } else { + user_ref.relays.write().join(" ") + }; + 'outer: loop { + let relays: Vec = if args.relays.is_empty() { + Interactor::default() + .input( + PromptInputParms::default() + .with_prompt("relays") + .with_default(default), + )? + .split(' ') + .map(std::string::ToString::to_string) + .collect() + } else { + args.relays.clone() + }; + let mut relay_urls = vec![]; + for r in &relays { + if let Ok(r) = RelayUrl::parse(r) { + relay_urls.push(r); + } else { + eprintln!("{r} is not a valid relay url"); + default = relays.join(" "); + continue 'outer; + } + } + break relay_urls; + } }; let earliest_unique_commit = match &args.earliest_unique_commit { @@ -415,6 +436,10 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { false, )?; + let relays = relays + .iter() + .map(std::string::ToString::to_string) + .collect::>(); // if yaml file doesnt exist or needs updating if match &repo_config_result { Ok(config) => { diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index 1965875..6c9d8eb 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs @@ -237,7 +237,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re if root_proposal_id.is_none() { if let Some(event) = events.first() { let event_bech32 = if let Some(relay) = repo_ref.relays.first() { - Nip19Event::new(event.id, vec![relay]).to_bech32()? + Nip19Event::new(event.id, vec![relay.to_string()]).to_bech32()? } else { event.id.to_bech32()? }; @@ -366,6 +366,7 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( relay_url: _, marker: _, public_key: _, + uppercase: false, }) => { let events = get_events_from_local_cache( git_repo_path, -- cgit v1.2.3