diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-11 16:21:44 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-06-13 09:09:00 +0100 |
| commit | f1b3fcc40ab666d8def97096d1942c274da9b279 (patch) | |
| tree | 05d6af0c5c1ad9baedb90ef652152fba6d46abf5 /src/repo_ref.rs | |
| parent | 7c6a5ab4c5e7a81c7442061029b9230748a6639d (diff) | |
chore: bump rust-nostr to v0.32.0
both nostr and nostr-sdk packages and also in test_utils
fix the many breaking changes
fix: ignore trailing slash when depuplicate relays for send events.
this was picked up as TagStandard::RelayMetadata has started adding
a traling slash.
refactor cli output test function `expect_send_with_progress` so that
relays can succeed / fail in a random order
Diffstat (limited to 'src/repo_ref.rs')
| -rw-r--r-- | src/repo_ref.rs | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/repo_ref.rs b/src/repo_ref.rs index d314e6d..9fb1f0c 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use std::{fs::File, io::BufReader, str::FromStr}; | 1 | use std::{fs::File, io::BufReader, str::FromStr}; |
| 2 | 2 | ||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::{nips::nip19::Nip19, FromBech32, PublicKey, Tag, ToBech32}; | 4 | use nostr::{nips::nip19::Nip19, FromBech32, PublicKey, Tag, TagStandard, ToBech32}; |
| 5 | use serde::{Deserialize, Serialize}; | 5 | use serde::{Deserialize, Serialize}; |
| 6 | 6 | ||
| 7 | #[cfg(not(test))] | 7 | #[cfg(not(test))] |
| @@ -31,7 +31,7 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 31 | type Error = anyhow::Error; | 31 | type Error = anyhow::Error; |
| 32 | 32 | ||
| 33 | fn try_from(event: nostr::Event) -> Result<Self> { | 33 | fn try_from(event: nostr::Event) -> Result<Self> { |
| 34 | if !event.kind.as_u64().eq(&REPO_REF_KIND) { | 34 | if !event.kind.as_u16().eq(&REPO_REF_KIND) { |
| 35 | bail!("incorrect kind"); | 35 | bail!("incorrect kind"); |
| 36 | } | 36 | } |
| 37 | let mut r = Self::default(); | 37 | let mut r = Self::default(); |
| @@ -49,12 +49,12 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("clone")) { | 51 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("clone")) { |
| 52 | r.git_server = t.as_vec().clone(); | 52 | r.git_server = t.clone().to_vec(); |
| 53 | r.git_server.remove(0); | 53 | r.git_server.remove(0); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("web")) { | 56 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("web")) { |
| 57 | r.web = t.as_vec().clone(); | 57 | r.web = t.clone().to_vec(); |
| 58 | r.web.remove(0); | 58 | r.web.remove(0); |
| 59 | } | 59 | } |
| 60 | 60 | ||
| @@ -67,12 +67,12 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("relays")) { | 69 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("relays")) { |
| 70 | r.relays = t.as_vec().clone(); | 70 | r.relays = t.clone().to_vec(); |
| 71 | r.relays.remove(0); | 71 | r.relays.remove(0); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("maintainers")) { | 74 | if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("maintainers")) { |
| 75 | let mut maintainers = t.as_vec().clone(); | 75 | let mut maintainers = t.clone().to_vec(); |
| 76 | maintainers.remove(0); | 76 | maintainers.remove(0); |
| 77 | if !maintainers.contains(&event.pubkey.to_string()) { | 77 | if !maintainers.contains(&event.pubkey.to_string()) { |
| 78 | r.maintainers.push(event.pubkey); | 78 | r.maintainers.push(event.pubkey); |
| @@ -90,7 +90,7 @@ impl TryFrom<nostr::Event> for RepoRef { | |||
| 90 | } | 90 | } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | pub static REPO_REF_KIND: u64 = 30_617; | 93 | pub static REPO_REF_KIND: u16 = 30_617; |
| 94 | 94 | ||
| 95 | impl RepoRef { | 95 | impl RepoRef { |
| 96 | pub fn to_event(&self, keys: &nostr::Keys) -> Result<nostr::Event> { | 96 | pub fn to_event(&self, keys: &nostr::Keys) -> Result<nostr::Event> { |
| @@ -99,7 +99,7 @@ impl RepoRef { | |||
| 99 | "", | 99 | "", |
| 100 | [ | 100 | [ |
| 101 | vec![ | 101 | vec![ |
| 102 | Tag::Identifier(if self.identifier.to_string().is_empty() { | 102 | Tag::identifier(if self.identifier.to_string().is_empty() { |
| 103 | // fiatjaf thought a random string. its not in the draft nip. | 103 | // fiatjaf thought a random string. its not in the draft nip. |
| 104 | // thread_rng() | 104 | // thread_rng() |
| 105 | // .sample_iter(&Alphanumeric) | 105 | // .sample_iter(&Alphanumeric) |
| @@ -117,27 +117,30 @@ impl RepoRef { | |||
| 117 | } else { | 117 | } else { |
| 118 | self.identifier.to_string() | 118 | self.identifier.to_string() |
| 119 | }), | 119 | }), |
| 120 | Tag::Reference(self.root_commit.to_string()), | 120 | Tag::from_standardized(TagStandard::Reference(self.root_commit.to_string())), |
| 121 | Tag::Name(self.name.clone()), | 121 | Tag::from_standardized(TagStandard::Name(self.name.clone())), |
| 122 | Tag::Description(self.description.clone()), | 122 | Tag::from_standardized(TagStandard::Description(self.description.clone())), |
| 123 | Tag::Generic( | 123 | Tag::custom( |
| 124 | nostr::TagKind::Custom("clone".to_string()), | 124 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), |
| 125 | self.git_server.clone(), | 125 | self.git_server.clone(), |
| 126 | ), | 126 | ), |
| 127 | Tag::Generic(nostr::TagKind::Custom("web".to_string()), self.web.clone()), | 127 | Tag::custom( |
| 128 | Tag::Generic( | 128 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("web")), |
| 129 | nostr::TagKind::Custom("relays".to_string()), | 129 | self.web.clone(), |
| 130 | ), | ||
| 131 | Tag::custom( | ||
| 132 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("relays")), | ||
| 130 | self.relays.clone(), | 133 | self.relays.clone(), |
| 131 | ), | 134 | ), |
| 132 | Tag::Generic( | 135 | Tag::custom( |
| 133 | nostr::TagKind::Custom("maintainers".to_string()), | 136 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("maintainers")), |
| 134 | self.maintainers | 137 | self.maintainers |
| 135 | .iter() | 138 | .iter() |
| 136 | .map(std::string::ToString::to_string) | 139 | .map(std::string::ToString::to_string) |
| 137 | .collect(), | 140 | .collect::<Vec<String>>(), |
| 138 | ), | 141 | ), |
| 139 | Tag::Generic( | 142 | Tag::custom( |
| 140 | nostr::TagKind::Custom("alt".to_string()), | 143 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")), |
| 141 | vec![format!("git repository: {}", self.name.clone())], | 144 | vec![format!("git repository: {}", self.name.clone())], |
| 142 | ), | 145 | ), |
| 143 | ], | 146 | ], |
| @@ -188,7 +191,7 @@ pub async fn fetch( | |||
| 188 | // somewhere within .git folder for future use and seek to get that next time | 191 | // somewhere within .git folder for future use and seek to get that next time |
| 189 | if let Some(event) = events | 192 | if let Some(event) = events |
| 190 | .iter() | 193 | .iter() |
| 191 | .filter(|e| e.kind.as_u64() == REPO_REF_KIND) | 194 | .filter(|e| e.kind.as_u16() == REPO_REF_KIND) |
| 192 | .max_by_key(|e| e.created_at) | 195 | .max_by_key(|e| e.created_at) |
| 193 | { | 196 | { |
| 194 | break event.clone(); | 197 | break event.clone(); |