From 57434ac39bd87317bda4c0a955d6214ce1123319 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Mon, 5 May 2025 14:41:56 +0000
Subject: [PATCH] chore: Handle `euc` in the `repo view` command
Signed-off-by: Awiteb
---
src/nostr_utils/traits.rs | 13 +++++++++++++
src/nostr_utils/utils.rs | 14 +++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 2a68311..22cfb5d 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -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(
+ &self,
+ kind: TagKind,
+ marker: &str,
+ f: impl FnOnce(&TagStandard) -> T,
+ ) -> Option {
+ self.filter_standardized(kind)
+ .find(|t| (*t).clone().to_vec().last().is_some_and(|m| m == marker))
+ .map(f)
+ }
}
diff --git a/src/nostr_utils/utils.rs b/src/nostr_utils/utils.rs
index 0b51947..2fde51a 100644
--- a/src/nostr_utils/utils.rs
+++ b/src/nostr_utils/utils.rs
@@ -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(tag: &TagStandard) -> Option {
+ tag_value(tag).parse().ok()
+}
+
/// Gets all values from the tag. If any value fails to parse, returns an empty
/// vector.
fn tag_values(tag: &TagStandard) -> Vec
@@ -56,7 +62,13 @@ pub fn event_into_repo(event: Event, repo_id: impl Into) -> 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),