From 557d9295e3fc6145073459da94905765de53be1e Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Sat, 24 May 2025 20:23:39 +0100 Subject: feat(init): make default ngit-relays configurable make the default set of ngit-relays configurable --- src/bin/ngit/cli.rs | 7 ++++--- src/bin/ngit/sub_commands/init.rs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/bin') diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 5461237..ce4e12e 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs @@ -40,10 +40,11 @@ pub const CUSTOMISE_TEMPLATE: &str = r" ========================== ngit settings are managed through the git config. -Currently the only settings not not reachable through standard commands relate to default hardcoded relays: +Currently the only settings not reachable through standard commands relate to default hardcoded relays: - - nostr.relay-default-set - must have at least 1 value - - nostr.relay-blaster-set + - nostr.ngit-relay-default-set - only used during `ngit init` + - nostr.relay-default-set - must have at least 1 value, all events send to repo relays, user write and default relays + - nostr.relay-blaster-set - only used for repo announcement events - nostr.relay-signer-fallback-set These take a string of semi-colon separated websocket URLs without spaces. For example: diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index f348c0d..1d9fda0 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -252,6 +252,15 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { args.blossoms.clone() }; + let fallback_ngit_relays = + if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.ngit-relay-default-set", None) { + s.split(';') + .filter_map(|url| normalize_ngit_relay_url(url).ok()) // Attempt to parse and filter out errors + .collect() + } else { + vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] + }; + let selected_ngit_relays = if has_server_and_relay_flags { // ignore so a script running `ngit init` can contiue without prompts vec![] @@ -265,8 +274,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { ); let mut selections: Vec = vec![true; options.len()]; // Initialize selections based on existing options let empty = options.is_empty(); - let fallbacks = vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()]; - for fallback in fallbacks { + for fallback in fallback_ngit_relays { // Check if any option contains the fallback as a substring if !options.iter().any(|option| option.contains(&fallback)) { options.push(fallback.clone()); // Add fallback if not found -- cgit v1.2.3