From b6407944cc8f670d33b828f7b77836ceeed2fcfa Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 22 May 2025 17:37:54 +0100 Subject: feat(init): add blossom add a blossom tag to the repo announcement --- src/bin/ngit/sub_commands/init.rs | 66 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'src/bin/ngit/sub_commands') diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 83e434f..4f82d5e 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -48,6 +48,9 @@ pub struct SubCommandArgs { /// relays contributors push patches and comments to relays: Vec, #[clap(short, long, value_parser, num_args = 1..)] + /// blossom servers + blossoms: Vec, + #[clap(short, long, value_parser, num_args = 1..)] /// npubs of other maintainers other_maintainers: Vec, #[clap(long)] @@ -222,6 +225,24 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { }; + let mut blossoms_defaults = if args.blossoms.is_empty() { + if let Some(repo_ref) = &repo_ref { + repo_ref + .blossoms + .iter() + .map(std::string::ToString::to_string) + .collect::>() + // } else if user_ref.blossoms.read().is_empty() { + // client.get_fallback_relays().clone() + } else { + vec![] + // user_ref.relays.read().clone() + } + } else { + args.blossoms.clone() + }; + + let selected_ngit_relays = if has_server_and_relay_flags { // ignore so a script running `ngit init` can contiue without prompts vec![] @@ -261,13 +282,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { git_server_defaults.push(clone_url); } } - if args.clone_url.is_empty() { + if args.relays.is_empty() { let relay_url = format_ngit_relay_url_as_relay_url(ngit_relay)?; if !relay_defaults.contains(&relay_url) { relay_defaults.push(relay_url); } } - // TODO blossom + if args.blossoms.is_empty() { + let blossom = format_ngit_blossom_url_as_relay_url(ngit_relay)?; + if !blossoms_defaults.contains(&blossom) { + blossoms_defaults.push(blossom); + } + } } let no_state = if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.nostate", None) { @@ -416,6 +442,33 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { } }; + let blossoms: Vec = { + if simple_mode || has_server_and_relay_flags { + blossoms_defaults + .iter().filter_map(|b| Url::parse(b).ok()).collect() + } else { + let selections: Vec = vec![true; blossoms_defaults.len()]; + if args.blossoms.is_empty() { + let selected = multi_select_with_custom_value( + "blossom servers", + "blossom server", + blossoms_defaults, + selections, + |s| { + Url::parse(s) + .map(|_| s.to_string()) + .context(format!("Invalid blossom URL format: {s}")) + }, + )?; + show_multi_input_prompt_success("nostr relays", &selected); + selected.iter().filter_map(|b| Url::parse(b).ok()).collect() + } else { + blossoms_defaults.iter().filter_map(|b| Url::parse(b).ok()).collect() + } + } + }; + + let default_maintainers = { let mut maintainers = vec![user_ref.public_key]; if args.other_maintainers.is_empty() { @@ -593,6 +646,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { git_server, web, relays: relays.clone(), + blossoms, trusted_maintainer: user_ref.public_key, maintainers: maintainers.clone(), events: HashMap::new(), @@ -875,6 +929,14 @@ fn format_ngit_relay_url_as_relay_url(url:&str) -> Result { Ok(format!("wss://{ngit_relay_url}")) } +fn format_ngit_blossom_url_as_relay_url(url:&str) -> Result { + let ngit_relay_url = normalize_ngit_relay_url(url)?; + if ngit_relay_url.contains("http://") { + return Ok(ngit_relay_url.to_string()) + } + Ok(format!("https://{ngit_relay_url}")) +} + fn extract_npub(s: &str) -> Result<&str> { // Find the starting index of "npub1" if let Some(start) = s.find("npub1") { -- cgit v1.2.3