From a9b2ebf8216be34950e54dd9a446dbdc0c9c744a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 6 Aug 2025 12:52:59 +0100 Subject: feat(send): PR fallback to user / custom grasp if use is maintainer, push PR to all repo git servers. if user has a fork, push to all git servers it lists, and repo grasp servers. if user hasn't got a fork but has a user grasp list and pushing push to repo grasp servers fails, create a personal-fork automatically at each user grasp server and push there. fallback to prompting user for either grasp servers or git server with write permission. if user provides grasp servers, suggesting adding to user preference list. --- src/bin/ngit/sub_commands/init.rs | 106 +++----------------------------------- 1 file changed, 8 insertions(+), 98 deletions(-) (limited to 'src/bin/ngit/sub_commands/init.rs') diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index eaaf83d..01fcaea 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -12,12 +12,12 @@ use console::{Style, Term}; use dialoguer::theme::{ColorfulTheme, Theme}; use ngit::{ UrlWithoutSlash, - cli_interactor::{PromptChoiceParms, PromptConfirmParms, PromptMultiChoiceParms}, + cli_interactor::{PromptChoiceParms, PromptConfirmParms, multi_select_with_custom_value}, client::{Params, send_events}, git::nostr_url::{CloneUrl, NostrUrlDecoded}, repo_ref::{ - detect_existing_grasp_servers, extract_npub, extract_pks, normalize_grasp_server_url, - save_repo_config_to_yaml, + detect_existing_grasp_servers, extract_npub, extract_pks, + format_grasp_server_url_as_relay_url, normalize_grasp_server_url, save_repo_config_to_yaml, }, }; use nostr::{ @@ -727,6 +727,11 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { web, relays: relays.clone(), blossoms, + hashtags: if let Some(repo_ref) = repo_ref { + repo_ref.hashtags + } else { + vec![] + }, trusted_maintainer: user_ref.public_key, maintainers_without_annoucnement: None, maintainers: maintainers.clone(), @@ -848,93 +853,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { Ok(()) } -fn multi_select_with_custom_value( - prompt: &str, - custom_choice_prompt: &str, - mut choices: Vec, - mut defaults: Vec, - validate_choice: F, -) -> Result> -where - F: Fn(&str) -> Result, -{ - let mut selected_choices = vec![]; - - // Loop to allow users to add more choices - loop { - // Add 'add another' option at the end of the choices - let mut current_choices = choices.clone(); - current_choices.push(if current_choices.is_empty() { - "add".to_string() - } else { - "add another".to_string() - }); - - // Create default selections based on the provided defaults - let mut current_defaults = defaults.clone(); - current_defaults.push(current_choices.len() == 1); // 'add another' should not be selected by default - - // Prompt for selections - let selected_indices: Vec = Interactor::default().multi_choice( - PromptMultiChoiceParms::default() - .with_prompt(prompt) - .dont_report() - .with_choices(current_choices.clone()) - .with_defaults(current_defaults), - )?; - - // Collect selected choices - selected_choices.clear(); // Clear previous selections to update - for &index in &selected_indices { - if index < choices.len() { - // Exclude 'add another' option - selected_choices.push(choices[index].clone()); - } - } - - // Check if 'add another' was selected - if selected_indices.contains(&(choices.len())) { - // Last index is 'add another' - let mut new_choice: String; - loop { - new_choice = Interactor::default().input( - PromptInputParms::default() - .with_prompt(custom_choice_prompt) - .dont_report() - .optional(), - )?; - - if new_choice.is_empty() { - break; - } - // Validate the new choice - match validate_choice(&new_choice) { - Ok(valid_choice) => { - new_choice = valid_choice; // Use the fixed version of the input - break; // Valid choice, exit the loop - } - Err(err) => { - // Inform the user about the validation error - println!("Error: {err}"); - } - } - } - - // Add the new choice to the choices vector - if !new_choice.is_empty() { - choices.push(new_choice.clone()); // Add new choice to the end of the list - selected_choices.push(new_choice); // Automatically select the new choice - defaults.push(true); // Set the new choice as selected by default - } - } else { - // Exit the loop if 'add another' was not selected - break; - } - } - - Ok(selected_choices) -} - fn format_grasp_server_url_as_clone_url( url: &str, public_key: &PublicKey, @@ -953,14 +871,6 @@ fn format_grasp_server_url_as_clone_url( )) } -fn format_grasp_server_url_as_relay_url(url: &str) -> Result { - let grasp_server_url = normalize_grasp_server_url(url)?; - if grasp_server_url.contains("http://") { - return Ok(grasp_server_url.replace("http://", "ws://")); - } - Ok(format!("wss://{grasp_server_url}")) -} - fn format_grasp_server_url_as_blossom_url(url: &str) -> Result { let grasp_server_url = normalize_grasp_server_url(url)?; if grasp_server_url.contains("http://") { -- cgit v1.2.3