diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/sub_commands/claim.rs | 13 | ||||
| -rw-r--r-- | src/sub_commands/repo_ref.rs | 51 |
2 files changed, 22 insertions, 42 deletions
diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs index cb6e99d..9a38f56 100644 --- a/src/sub_commands/claim.rs +++ b/src/sub_commands/claim.rs | |||
| @@ -67,12 +67,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 67 | 67 | ||
| 68 | println!("publishing repostory reference..."); | 68 | println!("publishing repostory reference..."); |
| 69 | 69 | ||
| 70 | let repo_event = RepoRef::default() | 70 | let repo_event = RepoRef { |
| 71 | .set_name(name) | 71 | name, |
| 72 | .set_description(description) | 72 | description, |
| 73 | .set_root_commit(root_commit.to_string()) | 73 | root_commit: root_commit.to_string(), |
| 74 | .set_relays(repo_relays.clone()) | 74 | relays: repo_relays.clone(), |
| 75 | .to_event(&keys)?; | 75 | } |
| 76 | .to_event(&keys)?; | ||
| 76 | 77 | ||
| 77 | send_events( | 78 | send_events( |
| 78 | &client, | 79 | &client, |
diff --git a/src/sub_commands/repo_ref.rs b/src/sub_commands/repo_ref.rs index 82580df..3b0b1b4 100644 --- a/src/sub_commands/repo_ref.rs +++ b/src/sub_commands/repo_ref.rs | |||
| @@ -3,36 +3,16 @@ use nostr::Tag; | |||
| 3 | 3 | ||
| 4 | #[derive(Default)] | 4 | #[derive(Default)] |
| 5 | pub struct RepoRef { | 5 | pub struct RepoRef { |
| 6 | name: String, | 6 | pub name: String, |
| 7 | description: String, | 7 | pub description: String, |
| 8 | root_commit: String, | 8 | pub root_commit: String, |
| 9 | relays: Vec<String>, | 9 | pub relays: Vec<String>, |
| 10 | // git_server: String, | 10 | // git_server: String, |
| 11 | // other maintainers | 11 | // other maintainers |
| 12 | // code languages and hashtags | 12 | // code languages and hashtags |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | impl RepoRef { | 15 | impl RepoRef { |
| 16 | pub fn set_name(&mut self, name: String) -> &mut Self { | ||
| 17 | self.name = name; | ||
| 18 | self | ||
| 19 | } | ||
| 20 | |||
| 21 | pub fn set_description(&mut self, description: String) -> &mut Self { | ||
| 22 | self.description = description; | ||
| 23 | self | ||
| 24 | } | ||
| 25 | |||
| 26 | pub fn set_root_commit(&mut self, root_commit: String) -> &mut Self { | ||
| 27 | self.root_commit = root_commit; | ||
| 28 | self | ||
| 29 | } | ||
| 30 | |||
| 31 | pub fn set_relays(&mut self, relays: Vec<String>) -> &mut Self { | ||
| 32 | self.relays = relays; | ||
| 33 | self | ||
| 34 | } | ||
| 35 | |||
| 36 | pub fn to_event(&self, keys: &nostr::Keys) -> Result<nostr::Event> { | 16 | pub fn to_event(&self, keys: &nostr::Keys) -> Result<nostr::Event> { |
| 37 | nostr_sdk::EventBuilder::new( | 17 | nostr_sdk::EventBuilder::new( |
| 38 | nostr::event::Kind::Custom(30017), | 18 | nostr::event::Kind::Custom(30017), |
| @@ -62,22 +42,21 @@ mod tests { | |||
| 62 | 42 | ||
| 63 | use super::*; | 43 | use super::*; |
| 64 | 44 | ||
| 45 | fn create() -> nostr::Event { | ||
| 46 | RepoRef { | ||
| 47 | name: "test name".to_string(), | ||
| 48 | description: "test description".to_string(), | ||
| 49 | root_commit: "23471389461".to_string(), | ||
| 50 | relays: vec!["ws://relay1.io".to_string(), "ws://relay2.io".to_string()], | ||
| 51 | } | ||
| 52 | .to_event(&TEST_KEY_1_KEYS) | ||
| 53 | .unwrap() | ||
| 54 | } | ||
| 55 | |||
| 65 | mod to_event { | 56 | mod to_event { |
| 66 | use super::*; | 57 | use super::*; |
| 67 | mod tags { | 58 | mod tags { |
| 68 | use super::*; | 59 | use super::*; |
| 69 | fn create() -> nostr::Event { | ||
| 70 | RepoRef::default() | ||
| 71 | .set_name("test name".to_string()) | ||
| 72 | .set_description("test description".to_string()) | ||
| 73 | .set_root_commit("23471389461".to_string()) | ||
| 74 | .set_relays(vec![ | ||
| 75 | "ws://relay1.io".to_string(), | ||
| 76 | "ws://relay2.io".to_string(), | ||
| 77 | ]) | ||
| 78 | .to_event(&TEST_KEY_1_KEYS) | ||
| 79 | .unwrap() | ||
| 80 | } | ||
| 81 | 60 | ||
| 82 | #[test] | 61 | #[test] |
| 83 | fn name() { | 62 | fn name() { |