diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-11-01 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-11-01 00:00:00 +0000 |
| commit | c37ceaf1c3e4371f320798bf423719a9a6fe71fd (patch) | |
| tree | e202a3eccb05f7ca0734cb4130ce69c1076452f5 /src/sub_commands/claim.rs | |
| parent | 0753e0bcdd3d606f8f0226a3980bcd817117abaa (diff) | |
refactor(claim) add RepoRef struct
enable wider usage of repoistory reference details
Diffstat (limited to 'src/sub_commands/claim.rs')
| -rw-r--r-- | src/sub_commands/claim.rs | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs index 5eb66bb..cb6e99d 100644 --- a/src/sub_commands/claim.rs +++ b/src/sub_commands/claim.rs | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | use anyhow::{Context, Result}; | 1 | use anyhow::{Context, Result}; |
| 2 | use nostr::{EventBuilder, Tag}; | ||
| 3 | 2 | ||
| 4 | use super::prs::create::send_events; | 3 | use super::prs::create::send_events; |
| 5 | #[cfg(not(test))] | 4 | #[cfg(not(test))] |
| @@ -10,7 +9,9 @@ use crate::{ | |||
| 10 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, | 9 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, |
| 11 | client::Connect, | 10 | client::Connect, |
| 12 | git::{Repo, RepoActions}, | 11 | git::{Repo, RepoActions}, |
| 13 | login, Cli, | 12 | login, |
| 13 | sub_commands::repo_ref::RepoRef, | ||
| 14 | Cli, | ||
| 14 | }; | 15 | }; |
| 15 | 16 | ||
| 16 | #[derive(Debug, clap::Args)] | 17 | #[derive(Debug, clap::Args)] |
| @@ -66,15 +67,16 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 66 | 67 | ||
| 67 | println!("publishing repostory reference..."); | 68 | println!("publishing repostory reference..."); |
| 68 | 69 | ||
| 70 | let repo_event = RepoRef::default() | ||
| 71 | .set_name(name) | ||
| 72 | .set_description(description) | ||
| 73 | .set_root_commit(root_commit.to_string()) | ||
| 74 | .set_relays(repo_relays.clone()) | ||
| 75 | .to_event(&keys)?; | ||
| 76 | |||
| 69 | send_events( | 77 | send_events( |
| 70 | &client, | 78 | &client, |
| 71 | vec![generate_repo_event( | 79 | vec![repo_event], |
| 72 | &name, | ||
| 73 | &description, | ||
| 74 | &repo_relays, | ||
| 75 | &root_commit.to_string(), | ||
| 76 | &keys, | ||
| 77 | )?], | ||
| 78 | user_ref.relays.write(), | 80 | user_ref.relays.write(), |
| 79 | repo_relays, | 81 | repo_relays, |
| 80 | !cli_args.disable_cli_spinners, | 82 | !cli_args.disable_cli_spinners, |
| @@ -83,32 +85,3 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 83 | 85 | ||
| 84 | Ok(()) | 86 | Ok(()) |
| 85 | } | 87 | } |
| 86 | |||
| 87 | fn generate_repo_event( | ||
| 88 | name: &str, | ||
| 89 | description: &str, | ||
| 90 | relays: &[String], | ||
| 91 | // git_server: String, | ||
| 92 | root_commit: &String, | ||
| 93 | keys: &nostr::Keys, | ||
| 94 | ) -> Result<nostr::Event> { | ||
| 95 | EventBuilder::new( | ||
| 96 | nostr::event::Kind::Custom(30017), | ||
| 97 | "", | ||
| 98 | &[ | ||
| 99 | vec![ | ||
| 100 | Tag::Identifier(root_commit.to_string()), | ||
| 101 | Tag::Reference(format!("r-{root_commit}")), | ||
| 102 | Tag::Name(name.to_owned()), | ||
| 103 | Tag::Description(description.to_owned()), | ||
| 104 | ], | ||
| 105 | relays.iter().map(|r| Tag::Relay(r.into())).collect(), | ||
| 106 | // git_servers | ||
| 107 | // other maintainers | ||
| 108 | // code languages and hashtags | ||
| 109 | ] | ||
| 110 | .concat(), | ||
| 111 | ) | ||
| 112 | .to_event(keys) | ||
| 113 | .context("failed to create pr event") | ||
| 114 | } | ||