update
This commit is contained in:
@@ -5,4 +5,5 @@ edition.workspace = true
|
||||
publish.workspace = true
|
||||
|
||||
[dependencies]
|
||||
gpui.workspace = true
|
||||
nostr.workspace = true
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use gpui::SharedString;
|
||||
use nostr::prelude::*;
|
||||
|
||||
/// Parsed NIP-34 repository announcement (plain data, ready for the UI).
|
||||
@@ -9,14 +10,14 @@ pub struct Announcement {
|
||||
pub created_at: Timestamp,
|
||||
/// Repository ID (`d` tag).
|
||||
pub id: String,
|
||||
pub name: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub name: Option<SharedString>,
|
||||
pub description: Option<SharedString>,
|
||||
/// Webpage URLs for browsing.
|
||||
pub web: Vec<String>,
|
||||
/// URLs for `git clone`.
|
||||
pub clone: Vec<String>,
|
||||
/// Relays the repository monitors for patches and issues.
|
||||
pub relays: Vec<String>,
|
||||
pub relays: Vec<RelayUrl>,
|
||||
/// Earliest unique commit ID (`r` tag with `euc` marker).
|
||||
pub euc: Option<String>,
|
||||
/// Other recognized maintainers.
|
||||
@@ -33,11 +34,11 @@ impl Announcement {
|
||||
}
|
||||
|
||||
let mut id: Option<String> = None;
|
||||
let mut name: Option<String> = None;
|
||||
let mut description: Option<String> = None;
|
||||
let mut name: Option<SharedString> = None;
|
||||
let mut description: Option<SharedString> = None;
|
||||
let mut web: Vec<String> = Vec::new();
|
||||
let mut clone: Vec<String> = Vec::new();
|
||||
let mut relays: Vec<String> = Vec::new();
|
||||
let mut relays: Vec<RelayUrl> = Vec::new();
|
||||
let mut euc: Option<String> = None;
|
||||
let mut maintainers: Vec<PublicKey> = Vec::new();
|
||||
let mut hashtags: Vec<String> = Vec::new();
|
||||
@@ -56,15 +57,13 @@ impl Announcement {
|
||||
}
|
||||
|
||||
match Nip34Tag::parse(tag.as_slice()) {
|
||||
Ok(Nip34Tag::Name(value)) => name = Some(value),
|
||||
Ok(Nip34Tag::Description(value)) => description = Some(value),
|
||||
Ok(Nip34Tag::Name(value)) => name = Some(value.into()),
|
||||
Ok(Nip34Tag::Description(value)) => description = Some(value.into()),
|
||||
Ok(Nip34Tag::Web(urls)) => web.extend(urls.into_iter().map(|url| url.to_string())),
|
||||
Ok(Nip34Tag::Clone(urls)) => {
|
||||
clone.extend(urls.into_iter().map(|url| url.to_string()))
|
||||
}
|
||||
Ok(Nip34Tag::Relays(urls)) => {
|
||||
relays.extend(urls.into_iter().map(|url| url.to_string()))
|
||||
}
|
||||
Ok(Nip34Tag::Relays(urls)) => relays.extend(urls),
|
||||
Ok(Nip34Tag::EarliestUniqueCommitId(commit)) => euc = Some(commit.to_string()),
|
||||
Ok(Nip34Tag::Maintainers(keys)) => maintainers.extend(keys),
|
||||
_ => {}
|
||||
@@ -144,7 +143,10 @@ mod tests {
|
||||
);
|
||||
assert_eq!(announcement.web, vec!["https://example.com/repo"]);
|
||||
assert_eq!(announcement.clone, vec!["https://example.com/repo.git"]);
|
||||
assert_eq!(announcement.relays, vec!["wss://relay.example.com"]);
|
||||
assert_eq!(
|
||||
announcement.relays,
|
||||
vec![RelayUrl::parse("wss://relay.example.com").unwrap()]
|
||||
);
|
||||
assert_eq!(
|
||||
announcement.euc.as_deref(),
|
||||
Some("aa231c4c6a5777dc89b42207b499891a344add5c")
|
||||
@@ -185,7 +187,10 @@ mod tests {
|
||||
|
||||
// An invalid URL keeps the whole clone tag from being parsed.
|
||||
assert!(announcement.clone.is_empty());
|
||||
assert_eq!(announcement.relays, vec!["wss://good.example.com"]);
|
||||
assert_eq!(
|
||||
announcement.relays,
|
||||
vec![RelayUrl::parse("wss://good.example.com").unwrap()]
|
||||
);
|
||||
assert!(announcement.maintainers.is_empty());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user