From a56acf5752bb8fc01c4c26df636c6c97dcf7fd9c Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 6 May 2025 11:30:13 +0000
Subject: [PATCH] chore: Trim the strings in `repo announce` command
Signed-off-by: Awiteb
---
src/cli/repo/announce.rs | 8 ++++----
src/nostr_utils/traits.rs | 1 +
src/nostr_utils/utils.rs | 5 +++++
3 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/src/cli/repo/announce.rs b/src/cli/repo/announce.rs
index caa61fd..f25b4d3 100644
--- a/src/cli/repo/announce.rs
+++ b/src/cli/repo/announce.rs
@@ -29,7 +29,7 @@ use nostr::{
use crate::{
cli::{CliOptions, CommandRunner},
error::N34Result,
- nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement},
+ nostr_utils::{NostrClient, traits::NewGitRepositoryAnnouncement, utils},
};
@@ -83,13 +83,13 @@ impl CommandRunner for AnnounceArgs {
let event = EventBuilder::new_git_repo(
self.repo_id,
- self.name,
- self.description,
+ self.name.map(utils::str_trim),
+ self.description.map(utils::str_trim),
self.web,
self.clone,
options.relays,
maintainers,
- self.labels,
+ self.labels.into_iter().map(utils::str_trim).collect(),
)?
.build(user_pubk);
let nevent = Nip19Event::new(event.id.expect("There is an id"))
diff --git a/src/nostr_utils/traits.rs b/src/nostr_utils/traits.rs
index 6c1afbd..cff3844 100644
--- a/src/nostr_utils/traits.rs
+++ b/src/nostr_utils/traits.rs
@@ -72,6 +72,7 @@ impl EventBuilder {
maintainers: Vec,
labels: Vec,
) -> N34Result {
+ let repo_id = repo_id.trim();
if repo_id.is_empty() || repo_id != repo_id.to_case(Case::Kebab) {
return Err(N34Error::InvalidRepoId);
}
diff --git a/src/nostr_utils/utils.rs b/src/nostr_utils/utils.rs
index 2fde51a..6b6b9dd 100644
--- a/src/nostr_utils/utils.rs
+++ b/src/nostr_utils/utils.rs
@@ -75,3 +75,8 @@ pub fn event_into_repo(event: Event, repo_id: impl Into) -> GitRepositor
maintainers: tags.dmap_tag(TagKind::Maintainers, tag_values),
}
}
+
+/// Returns a new string with leading and trailing whitespace removed.
+pub fn str_trim(s: String) -> String {
+ s.trim().to_owned()
+}