From 3e52ecb609f8424cffb2e6398c599aa78224825a Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 12 Dec 2023 00:00:00 +0000 Subject: feat(claim) create yaml add maintainers and relays - create yaml file with maintainers and relays - add maintainers to repo event - add current user as maintainer - custom repo relays from cli argument - save git-server in repo event --- src/sub_commands/claim.rs | 52 +++++++++++++++++++++++++++++++++++++----- src/sub_commands/prs/create.rs | 2 +- src/sub_commands/prs/list.rs | 1 + src/sub_commands/pull.rs | 1 + src/sub_commands/push.rs | 1 + 5 files changed, 50 insertions(+), 7 deletions(-) (limited to 'src/sub_commands') diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs index c0d26dd..2573267 100644 --- a/src/sub_commands/claim.rs +++ b/src/sub_commands/claim.rs @@ -10,7 +10,7 @@ use crate::{ client::Connect, git::{Repo, RepoActions}, login, - repo_ref::RepoRef, + repo_ref::{extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef}, Cli, }; @@ -22,6 +22,9 @@ pub struct SubCommandArgs { #[clap(short, long)] /// optional description description: Option, + #[clap(short, long, value_parser, num_args = 1..)] + /// relays contributors push patches and comments to + relays: Vec, } pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { @@ -37,6 +40,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { // TODO: check for empty repo // TODO: check for existing maintaiers file + + let repo_config_result = get_repo_config_from_yaml(&git_repo); // TODO: check for other claims let name = match &args.title { @@ -50,6 +55,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .input(PromptInputParms::default().with_prompt("description (Optional)"))?, }; + let git_server = git_repo.get_origin_url()?; + #[cfg(not(test))] let mut client = Client::default(); #[cfg(test)] @@ -59,11 +66,41 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { client.set_keys(&keys).await; - // TODO: choice input defaulting to user relay list filtered by non paid relays - let repo_relays: Vec = vec![ - "ws://localhost:8055".to_string(), - "ws://localhost:8056".to_string(), - ]; + let mut maintainers = vec![keys.public_key()]; + + let repo_relays: Vec = if !args.relays.is_empty() { + args.relays.clone() + } else if let Ok(config) = &repo_config_result { + config.relays.clone() + } else { + // TODO: choice input defaulting to user relay list filtered by non paid relays + // TODO: allow manual input for more relays + // TODO: reccommend some free relays + user_ref.relays.write() + }; + + if let Ok(config) = &repo_config_result { + maintainers = extract_pks(config.maintainers.clone())?; + } + + // 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(&repo_relays)) + } + Err(_) => true, + } { + save_repo_config_to_yaml(&git_repo, maintainers.clone(), repo_relays.clone())?; + println!( + "maintainers.yaml {}. commit and push.", + if repo_config_result.is_err() { + "created" + } else { + "updated" + } + ); + } println!("publishing repostory reference..."); @@ -71,10 +108,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { name, description, root_commit: root_commit.to_string(), + git_server, relays: repo_relays.clone(), + maintainers, } .to_event(&keys)?; + // TODO: send repo event to blaster send_events( &client, vec![repo_event], diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index 5c4e578..5e41a56 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs @@ -100,12 +100,12 @@ pub async fn launch( generate_pr_and_patch_events(&title, &description, &to_branch, &git_repo, &ahead, &keys)?; let repo_ref = repo_ref::fetch( + &git_repo, git_repo .get_root_commit(&to_branch) .context("failed to get root commit of the repository")? .to_string(), &client, - // TODO: get relay list from local yaml file user_ref.relays.write(), ) .await?; diff --git a/src/sub_commands/prs/list.rs b/src/sub_commands/prs/list.rs index 13f29fd..a6aa8b7 100644 --- a/src/sub_commands/prs/list.rs +++ b/src/sub_commands/prs/list.rs @@ -45,6 +45,7 @@ pub async fn launch( let client = ::default(); let repo_ref = repo_ref::fetch( + &git_repo, root_commit.to_string(), &client, client.get_more_fallback_relays().clone(), diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index a6513e8..a656e09 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs @@ -38,6 +38,7 @@ pub async fn launch() -> Result<()> { let client = ::default(); let repo_ref = repo_ref::fetch( + &git_repo, root_commit.to_string(), &client, client.get_more_fallback_relays().clone(), diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 968aa0a..7c64bb2 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs @@ -41,6 +41,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { let mut client = ::default(); let repo_ref = repo_ref::fetch( + &git_repo, root_commit.to_string(), &client, client.get_more_fallback_relays().clone(), -- cgit v1.2.3