@@ -15,10 +15,7 @@
|
|||||||
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
|
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
|
||||||
|
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use nostr::{
|
use nostr::{event::Kind, filter::Filter};
|
||||||
event::{Kind, TagKind},
|
|
||||||
filter::Filter,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{
|
cli::{
|
||||||
@@ -29,7 +26,7 @@ use crate::{
|
|||||||
error::{N34Error, N34Result},
|
error::{N34Error, N34Result},
|
||||||
nostr_utils::{
|
nostr_utils::{
|
||||||
NostrClient,
|
NostrClient,
|
||||||
traits::{NaddrsUtils, ReposUtils},
|
traits::{GitIssueUtils, NaddrsUtils, ReposUtils},
|
||||||
utils,
|
utils,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -77,24 +74,9 @@ impl CommandRunner for ViewArgs {
|
|||||||
.await?
|
.await?
|
||||||
.ok_or(N34Error::CanNotFoundIssue)?;
|
.ok_or(N34Error::CanNotFoundIssue)?;
|
||||||
|
|
||||||
let issue_subject = utils::smart_wrap(
|
let issue_subject = utils::smart_wrap(issue.extract_issue_subject(), 70);
|
||||||
issue
|
|
||||||
.tags
|
|
||||||
.find(TagKind::Subject)
|
|
||||||
.and_then(|t| t.content())
|
|
||||||
.unwrap_or("N/A"),
|
|
||||||
70,
|
|
||||||
);
|
|
||||||
let issue_author = client.get_username(issue.pubkey).await;
|
let issue_author = client.get_username(issue.pubkey).await;
|
||||||
let mut issue_labels = utils::smart_wrap(
|
let mut issue_labels = utils::smart_wrap(&issue.extract_issue_labels(), 70);
|
||||||
&issue
|
|
||||||
.tags
|
|
||||||
.filter(TagKind::t())
|
|
||||||
.filter_map(|t| t.content().map(|l| format!("#{l}")))
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join(", "),
|
|
||||||
70,
|
|
||||||
);
|
|
||||||
|
|
||||||
if issue_labels.is_empty() {
|
if issue_labels.is_empty() {
|
||||||
issue_labels = "\n".to_owned();
|
issue_labels = "\n".to_owned();
|
||||||
|
|||||||
@@ -262,3 +262,27 @@ impl Event {
|
|||||||
.map_err(|err| N34Error::InvalidEvent(format!("Invalid event ID in `e` tag: {err}")))
|
.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::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user