upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/ngit
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit')
-rw-r--r--src/bin/ngit/sub_commands/init.rs63
-rw-r--r--src/bin/ngit/sub_commands/send.rs3
2 files changed, 46 insertions, 20 deletions
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;
3use anyhow::{Context, Result}; 3use anyhow::{Context, Result};
4use ngit::cli_interactor::PromptConfirmParms; 4use ngit::cli_interactor::PromptConfirmParms;
5use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32}; 5use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32};
6use nostr_sdk::Kind; 6use nostr_sdk::{Kind, RelayUrl};
7 7
8use crate::{ 8use crate::{
9 cli::{extract_signer_cli_arguments, Cli}, 9 cli::{extract_signer_cli_arguments, Cli},
@@ -323,24 +323,45 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
323 323
324 // TODO: check if relays are free to post to so contributors can submit patches 324 // TODO: check if relays are free to post to so contributors can submit patches
325 // TODO: recommend some reliable free ones 325 // TODO: recommend some reliable free ones
326 let relays: Vec<String> = if args.relays.is_empty() { 326 let relays: Vec<RelayUrl> = {
327 Interactor::default() 327 let mut default = if let Ok(config) = &repo_config_result {
328 .input( 328 config.relays.clone().join(" ")
329 PromptInputParms::default() 329 } else if let Some(repo_ref) = &repo_ref {
330 .with_prompt("relays") 330 repo_ref
331 .with_default(if let Ok(config) = &repo_config_result { 331 .relays
332 config.relays.clone().join(" ") 332 .iter()
333 } else if let Some(repo_ref) = &repo_ref { 333 .map(std::string::ToString::to_string)
334 repo_ref.relays.clone().join(" ") 334 .collect::<Vec<String>>()
335 } else { 335 .join(" ")
336 user_ref.relays.write().join(" ") 336 } else {
337 }), 337 user_ref.relays.write().join(" ")
338 )? 338 };
339 .split(' ') 339 'outer: loop {
340 .map(std::string::ToString::to_string) 340 let relays: Vec<String> = if args.relays.is_empty() {
341 .collect() 341 Interactor::default()
342 } else { 342 .input(
343 args.relays.clone() 343 PromptInputParms::default()
344 .with_prompt("relays")
345 .with_default(default),
346 )?
347 .split(' ')
348 .map(std::string::ToString::to_string)
349 .collect()
350 } else {
351 args.relays.clone()
352 };
353 let mut relay_urls = vec![];
354 for r in &relays {
355 if let Ok(r) = RelayUrl::parse(r) {
356 relay_urls.push(r);
357 } else {
358 eprintln!("{r} is not a valid relay url");
359 default = relays.join(" ");
360 continue 'outer;
361 }
362 }
363 break relay_urls;
364 }
344 }; 365 };
345 366
346 let earliest_unique_commit = match &args.earliest_unique_commit { 367 let earliest_unique_commit = match &args.earliest_unique_commit {
@@ -415,6 +436,10 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
415 false, 436 false,
416 )?; 437 )?;
417 438
439 let relays = relays
440 .iter()
441 .map(std::string::ToString::to_string)
442 .collect::<Vec<String>>();
418 // if yaml file doesnt exist or needs updating 443 // if yaml file doesnt exist or needs updating
419 if match &repo_config_result { 444 if match &repo_config_result {
420 Ok(config) => { 445 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
237 if root_proposal_id.is_none() { 237 if root_proposal_id.is_none() {
238 if let Some(event) = events.first() { 238 if let Some(event) = events.first() {
239 let event_bech32 = if let Some(relay) = repo_ref.relays.first() { 239 let event_bech32 = if let Some(relay) = repo_ref.relays.first() {
240 Nip19Event::new(event.id, vec![relay]).to_bech32()? 240 Nip19Event::new(event.id, vec![relay.to_string()]).to_bech32()?
241 } else { 241 } else {
242 event.id.to_bech32()? 242 event.id.to_bech32()?
243 }; 243 };
@@ -366,6 +366,7 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to(
366 relay_url: _, 366 relay_url: _,
367 marker: _, 367 marker: _,
368 public_key: _, 368 public_key: _,
369 uppercase: false,
369 }) => { 370 }) => {
370 let events = get_events_from_local_cache( 371 let events = get_events_from_local_cache(
371 git_repo_path, 372 git_repo_path,