From 7e479f3c7a1cd36568d7fbf20df5f2321429148e Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 1 Jul 2025 15:07:04 +0000
Subject: [PATCH] chore: issues utils
Signed-off-by: Awiteb
---
src/cli/commands/issue/view.rs | 26 ++++----------------------
src/nostr_utils/traits.rs | 24 ++++++++++++++++++++++++
2 files changed, 28 insertions(+), 22 deletions(-)
diff --git a/src/cli/commands/issue/view.rs b/src/cli/commands/issue/view.rs
index 7e3164d..f56568d 100644
--- a/src/cli/commands/issue/view.rs
+++ b/src/cli/commands/issue/view.rs
@@ -15,10 +15,7 @@
// along with this program. If not, see .
use clap::Args;
-use nostr::{
- event::{Kind, TagKind},
- filter::Filter,
-};
+use nostr::{event::Kind, filter::Filter};
use crate::{
cli::{
@@ -29,7 +26,7 @@ use crate::{
error::{N34Error, N34Result},
nostr_utils::{
NostrClient,
- traits::{NaddrsUtils, ReposUtils},
+ traits::{GitIssueUtils, NaddrsUtils, ReposUtils},
utils,
},
};
@@ -77,24 +74,9 @@ impl CommandRunner for ViewArgs {
.await?
.ok_or(N34Error::CanNotFoundIssue)?;
- let issue_subject = utils::smart_wrap(
- issue
- .tags
- .find(TagKind::Subject)
- .and_then(|t| t.content())
- .unwrap_or("N/A"),
- 70,
- );
+ let issue_subject = utils::smart_wrap(issue.extract_issue_subject(), 70);
let issue_author = client.get_username(issue.pubkey).await;
- let mut issue_labels = utils::smart_wrap(
- &issue
- .tags
- .filter(TagKind::t())
- .filter_map(|t| t.content().map(|l| format!("#{l}")))
- .collect::>()
- .join(", "),
- 70,
- );
+ let mut issue_labels = utils::smart_wrap(&issue.extract_issue_labels(), 70);
if issue_labels.is_empty() {
issue_labels = "\n".to_owned();
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 20bb825..5dee402 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -262,3 +262,27 @@ impl Event {
.map_err(|err| N34Error::InvalidEvent(format!("Invalid event ID in `e` tag: {err}")))
}
}
+
+/// Utility functions for working with issue events
+#[easy_ext::ext(GitIssueUtils)]
+impl Event {
+ /// Gets the subject line of the issue or "N/A" if none exists
+ #[inline]
+ pub fn extract_issue_subject(&self) -> &str {
+ self.tags
+ .find(TagKind::Subject)
+ .and_then(|t| t.content())
+ .unwrap_or("N/A")
+ }
+
+ /// Gets all issue labels formatted as comma-separated hashtags (e.g. "#bug,
+ /// #feature")
+ #[inline]
+ pub fn extract_issue_labels(&self) -> String {
+ self.tags
+ .filter(TagKind::t())
+ .filter_map(|t| t.content().map(|l| format!("#{l}")))
+ .collect::>()
+ .join(", ")
+ }
+}