diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-12-12 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-12-12 00:00:00 +0000 |
| commit | 3e52ecb609f8424cffb2e6398c599aa78224825a (patch) | |
| tree | 5c199510c10e206d6c6801dbabdae9691c03341c /src/sub_commands/claim.rs | |
| parent | 6d3c9218d2d3320f5d7fb9b9ede8750e947b70e8 (diff) | |
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
Diffstat (limited to 'src/sub_commands/claim.rs')
| -rw-r--r-- | src/sub_commands/claim.rs | 52 |
1 files changed, 46 insertions, 6 deletions
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::{ | |||
| 10 | client::Connect, | 10 | client::Connect, |
| 11 | git::{Repo, RepoActions}, | 11 | git::{Repo, RepoActions}, |
| 12 | login, | 12 | login, |
| 13 | repo_ref::RepoRef, | 13 | repo_ref::{extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, RepoRef}, |
| 14 | Cli, | 14 | Cli, |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| @@ -22,6 +22,9 @@ pub struct SubCommandArgs { | |||
| 22 | #[clap(short, long)] | 22 | #[clap(short, long)] |
| 23 | /// optional description | 23 | /// optional description |
| 24 | description: Option<String>, | 24 | description: Option<String>, |
| 25 | #[clap(short, long, value_parser, num_args = 1..)] | ||
| 26 | /// relays contributors push patches and comments to | ||
| 27 | relays: Vec<String>, | ||
| 25 | } | 28 | } |
| 26 | 29 | ||
| 27 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | 30 | pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { |
| @@ -37,6 +40,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 37 | 40 | ||
| 38 | // TODO: check for empty repo | 41 | // TODO: check for empty repo |
| 39 | // TODO: check for existing maintaiers file | 42 | // TODO: check for existing maintaiers file |
| 43 | |||
| 44 | let repo_config_result = get_repo_config_from_yaml(&git_repo); | ||
| 40 | // TODO: check for other claims | 45 | // TODO: check for other claims |
| 41 | 46 | ||
| 42 | let name = match &args.title { | 47 | let name = match &args.title { |
| @@ -50,6 +55,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 50 | .input(PromptInputParms::default().with_prompt("description (Optional)"))?, | 55 | .input(PromptInputParms::default().with_prompt("description (Optional)"))?, |
| 51 | }; | 56 | }; |
| 52 | 57 | ||
| 58 | let git_server = git_repo.get_origin_url()?; | ||
| 59 | |||
| 53 | #[cfg(not(test))] | 60 | #[cfg(not(test))] |
| 54 | let mut client = Client::default(); | 61 | let mut client = Client::default(); |
| 55 | #[cfg(test)] | 62 | #[cfg(test)] |
| @@ -59,11 +66,41 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 59 | 66 | ||
| 60 | client.set_keys(&keys).await; | 67 | client.set_keys(&keys).await; |
| 61 | 68 | ||
| 62 | // TODO: choice input defaulting to user relay list filtered by non paid relays | 69 | let mut maintainers = vec![keys.public_key()]; |
| 63 | let repo_relays: Vec<String> = vec![ | 70 | |
| 64 | "ws://localhost:8055".to_string(), | 71 | let repo_relays: Vec<String> = if !args.relays.is_empty() { |
| 65 | "ws://localhost:8056".to_string(), | 72 | args.relays.clone() |
| 66 | ]; | 73 | } else if let Ok(config) = &repo_config_result { |
| 74 | config.relays.clone() | ||
| 75 | } else { | ||
| 76 | // TODO: choice input defaulting to user relay list filtered by non paid relays | ||
| 77 | // TODO: allow manual input for more relays | ||
| 78 | // TODO: reccommend some free relays | ||
| 79 | user_ref.relays.write() | ||
| 80 | }; | ||
| 81 | |||
| 82 | if let Ok(config) = &repo_config_result { | ||
| 83 | maintainers = extract_pks(config.maintainers.clone())?; | ||
| 84 | } | ||
| 85 | |||
| 86 | // if yaml file doesnt exist or needs updating | ||
| 87 | if match &repo_config_result { | ||
| 88 | Ok(config) => { | ||
| 89 | !(extract_pks(config.maintainers.clone())?.eq(&maintainers) | ||
| 90 | && config.relays.eq(&repo_relays)) | ||
| 91 | } | ||
| 92 | Err(_) => true, | ||
| 93 | } { | ||
| 94 | save_repo_config_to_yaml(&git_repo, maintainers.clone(), repo_relays.clone())?; | ||
| 95 | println!( | ||
| 96 | "maintainers.yaml {}. commit and push.", | ||
| 97 | if repo_config_result.is_err() { | ||
| 98 | "created" | ||
| 99 | } else { | ||
| 100 | "updated" | ||
| 101 | } | ||
| 102 | ); | ||
| 103 | } | ||
| 67 | 104 | ||
| 68 | println!("publishing repostory reference..."); | 105 | println!("publishing repostory reference..."); |
| 69 | 106 | ||
| @@ -71,10 +108,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 71 | name, | 108 | name, |
| 72 | description, | 109 | description, |
| 73 | root_commit: root_commit.to_string(), | 110 | root_commit: root_commit.to_string(), |
| 111 | git_server, | ||
| 74 | relays: repo_relays.clone(), | 112 | relays: repo_relays.clone(), |
| 113 | maintainers, | ||
| 75 | } | 114 | } |
| 76 | .to_event(&keys)?; | 115 | .to_event(&keys)?; |
| 77 | 116 | ||
| 117 | // TODO: send repo event to blaster | ||
| 78 | send_events( | 118 | send_events( |
| 79 | &client, | 119 | &client, |
| 80 | vec![repo_event], | 120 | vec![repo_event], |