chore: Handle euc in the repo view command
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
@@ -33,4 +33,17 @@ impl Tags {
|
||||
{
|
||||
self.map_tag(kind, f).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Finds the first standard tag of the given kind with the specified
|
||||
/// marker, then applies the function to the tag and returns the result.
|
||||
pub fn map_marker<T>(
|
||||
&self,
|
||||
kind: TagKind,
|
||||
marker: &str,
|
||||
f: impl FnOnce(&TagStandard) -> T,
|
||||
) -> Option<T> {
|
||||
self.filter_standardized(kind)
|
||||
.find(|t| (*t).clone().to_vec().last().is_some_and(|m| m == marker))
|
||||
.map(f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user