upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/claim.rs2
-rw-r--r--src/sub_commands/mod.rs1
-rw-r--r--src/sub_commands/repo_ref.rs116
3 files changed, 1 insertions, 118 deletions
diff --git a/src/sub_commands/claim.rs b/src/sub_commands/claim.rs
index 9a38f56..c0d26dd 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 sub_commands::repo_ref::RepoRef, 13 repo_ref::RepoRef,
14 Cli, 14 Cli,
15}; 15};
16 16
diff --git a/src/sub_commands/mod.rs b/src/sub_commands/mod.rs
index 9e9f602..6e99ca5 100644
--- a/src/sub_commands/mod.rs
+++ b/src/sub_commands/mod.rs
@@ -1,4 +1,3 @@
1pub mod claim; 1pub mod claim;
2pub mod login; 2pub mod login;
3pub mod prs; 3pub mod prs;
4pub mod repo_ref;
diff --git a/src/sub_commands/repo_ref.rs b/src/sub_commands/repo_ref.rs
deleted file mode 100644
index 3b0b1b4..0000000
--- a/src/sub_commands/repo_ref.rs
+++ /dev/null
@@ -1,116 +0,0 @@
1use anyhow::{Context, Result};
2use nostr::Tag;
3
4#[derive(Default)]
5pub struct RepoRef {
6 pub name: String,
7 pub description: String,
8 pub root_commit: String,
9 pub relays: Vec<String>,
10 // git_server: String,
11 // other maintainers
12 // code languages and hashtags
13}
14
15impl RepoRef {
16 pub fn to_event(&self, keys: &nostr::Keys) -> Result<nostr::Event> {
17 nostr_sdk::EventBuilder::new(
18 nostr::event::Kind::Custom(30017),
19 "",
20 &[
21 vec![
22 Tag::Identifier(self.root_commit.to_string()),
23 Tag::Reference(format!("r-{}", self.root_commit)),
24 Tag::Name(self.name.clone()),
25 Tag::Description(self.description.clone()),
26 ],
27 self.relays.iter().map(|r| Tag::Relay(r.into())).collect(),
28 // git_servers
29 // other maintainers
30 // code languages and hashtags
31 ]
32 .concat(),
33 )
34 .to_event(keys)
35 .context("failed to create repository reference event")
36 }
37}
38
39#[cfg(test)]
40mod tests {
41 use test_utils::*;
42
43 use super::*;
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
56 mod to_event {
57 use super::*;
58 mod tags {
59 use super::*;
60
61 #[test]
62 fn name() {
63 assert!(
64 create()
65 .tags
66 .iter()
67 .any(|t| t.as_vec()[0].eq("name") && t.as_vec()[1].eq("test name"))
68 )
69 }
70 #[test]
71 fn description() {
72 assert!(create().tags.iter().any(
73 |t| t.as_vec()[0].eq("description") && t.as_vec()[1].eq("test description")
74 ))
75 }
76
77 #[test]
78 fn root_commit_as_d_replaceable_event_identifier() {
79 assert!(
80 create()
81 .tags
82 .iter()
83 .any(|t| t.as_vec()[0].eq("d") && t.as_vec()[1].eq("23471389461"))
84 )
85 }
86
87 #[test]
88 fn root_commit_as_reference() {
89 assert!(
90 create()
91 .tags
92 .iter()
93 .any(|t| t.as_vec()[0].eq("r") && t.as_vec()[1].eq("r-23471389461"))
94 )
95 }
96
97 #[test]
98 fn relays() {
99 let event = create();
100 let relay_tags = event
101 .tags
102 .iter()
103 .filter(|t| t.as_vec()[0].eq("relay"))
104 .collect::<Vec<&nostr::Tag>>();
105 assert_eq!(relay_tags[0].as_vec().len(), 2);
106 assert_eq!(relay_tags[0].as_vec()[1], "ws://relay1.io");
107 assert_eq!(relay_tags[1].as_vec()[1], "ws://relay2.io");
108 }
109
110 #[test]
111 fn no_other_tags() {
112 assert_eq!(create().tags.len(), 6)
113 }
114 }
115 }
116}