chore: Handle euc in the repo view command

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-05 14:41:56 +00:00
parent 99e46d7633
commit 57434ac39b
2 changed files with 26 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ use std::{fmt, str::FromStr};
use nostr::{
event::{Event, TagKind, TagStandard},
filter::{Alphabet, SingleLetterTag},
nips::nip34::GitRepositoryAnnouncement,
};
@@ -28,6 +29,11 @@ fn tag_value(tag: &TagStandard) -> String {
tag.clone().to_vec().remove(1)
}
/// Parses the tag value into type `T` if possible.
fn parse_value<T: FromStr>(tag: &TagStandard) -> Option<T> {
tag_value(tag).parse().ok()
}
/// Gets all values from the tag. If any value fails to parse, returns an empty
/// vector.
fn tag_values<T>(tag: &TagStandard) -> Vec<T>
@@ -56,7 +62,13 @@ pub fn event_into_repo(event: Event, repo_id: impl Into<String>) -> GitRepositor
id: repo_id.into(),
name: tags.map_tag(TagKind::Name, tag_value),
description: tags.map_tag(TagKind::Description, tag_value),
euc: None,
euc: tags
.map_marker(
TagKind::SingleLetter(SingleLetterTag::lowercase(Alphabet::R)),
"euc",
parse_value,
)
.flatten(),
web: tags.dmap_tag(TagKind::Web, tag_values),
clone: tags.dmap_tag(TagKind::Clone, tag_values),
relays: tags.dmap_tag(TagKind::Relays, tag_values),