From d3bf05365ff2d360d53abe2324f42d98f0c1779c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 23 Feb 2024 14:23:26 +0000 Subject: feat(init): improve copy order move instruction to commit and push maintainers.yaml to end of file --- src/sub_commands/init.rs | 47 +++++++++++++++++++++++------------------------ tests/init.rs | 13 ++++++++++--- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 54b6156..4f098c0 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -279,28 +279,6 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { } }; - // if yaml file doesnt exist or needs updating - if match &repo_config_result { - Ok(config) => { - !(extract_pks(config.maintainers.clone())?.eq(&maintainers) - && config.relays.eq(&relays)) - } - Err(_) => true, - } { - save_repo_config_to_yaml(&git_repo, maintainers.clone(), relays.clone())?; - println!( - "maintainers.yaml {}. commit and push.", - if repo_config_result.is_err() { - "created" - } else { - "updated" - } - ); - println!( - "this enables existing contributors to automatically fetch your repo event (instead of one from a pubkey pretending to be the maintainer)" - ); - } - println!("publishing repostory reference..."); let repo_event = RepoRef { @@ -311,7 +289,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { git_server, web, relays: relays.clone(), - maintainers, + maintainers: maintainers.clone(), } .to_event(&keys)?; @@ -319,10 +297,31 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { &client, vec![repo_event], user_ref.relays.write(), - relays, + relays.clone(), !cli_args.disable_cli_spinners, ) .await?; + // if yaml file doesnt exist or needs updating + if match &repo_config_result { + Ok(config) => { + !(extract_pks(config.maintainers.clone())?.eq(&maintainers) + && config.relays.eq(&relays)) + } + Err(_) => true, + } { + save_repo_config_to_yaml(&git_repo, maintainers.clone(), relays.clone())?; + println!( + "maintainers.yaml {}. commit and push.", + if repo_config_result.is_err() { + "created" + } else { + "updated" + } + ); + println!( + "this optional file enables existing contributors to automatically fetch your repo event (instead of one from a pubkey pretending to be the maintainer)" + ); + } Ok(()) } diff --git a/tests/init.rs b/tests/init.rs index d733643..7c69784 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -7,12 +7,18 @@ fn expect_msgs_first(p: &mut CliTester) -> Result<()> { p.expect("\r")?; p.expect("logged in as fred\r\n")?; // // p.expect("searching for existing claims on repository...\r\n")?; - p.expect("maintainers.yaml created. commit and push.\r\n")?; - p.expect("this enables existing contributors to automatically fetch your repo event (instead of one from a pubkey pretending to be the maintainer) publishing repostory reference...\r\n")?; p.expect("publishing repostory reference...\r\n")?; Ok(()) } +fn expect_msgs_after(p: &mut CliTester) -> Result<()> { + p.expect_after_whitespace("maintainers.yaml created. commit and push.\r\n")?; + p.expect( + "this optional file enables existing contributors to automatically fetch your repo event (instead of one from a pubkey pretending to be the maintainer)\r\n", + )?; + Ok(()) +} + fn get_cli_args() -> Vec<&'static str> { vec![ "--nsec", @@ -478,7 +484,8 @@ mod when_repo_not_previously_claimed { ], 1, )?; - p.expect_end_with_whitespace()?; + expect_msgs_after(&mut p)?; + p.expect_end()?; for p in [51, 52, 53, 55, 56, 57] { relay::shutdown_relay(8000 + p)?; } -- cgit v1.2.3