chore: Trim the strings in repo announce command

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-06 11:30:13 +00:00
parent 9b4dfb9374
commit a56acf5752
3 changed files with 10 additions and 4 deletions

View File

@@ -29,7 +29,7 @@ use nostr::{
use crate::{ use crate::{
cli::{CliOptions, CommandRunner}, cli::{CliOptions, CommandRunner},
error::N34Result, 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( let event = EventBuilder::new_git_repo(
self.repo_id, self.repo_id,
self.name, self.name.map(utils::str_trim),
self.description, self.description.map(utils::str_trim),
self.web, self.web,
self.clone, self.clone,
options.relays, options.relays,
maintainers, maintainers,
self.labels, self.labels.into_iter().map(utils::str_trim).collect(),
)? )?
.build(user_pubk); .build(user_pubk);
let nevent = Nip19Event::new(event.id.expect("There is an id")) let nevent = Nip19Event::new(event.id.expect("There is an id"))

View File

@@ -72,6 +72,7 @@ impl EventBuilder {
maintainers: Vec<PublicKey>, maintainers: Vec<PublicKey>,
labels: Vec<String>, labels: Vec<String>,
) -> N34Result<EventBuilder> { ) -> N34Result<EventBuilder> {
let repo_id = repo_id.trim();
if repo_id.is_empty() || repo_id != repo_id.to_case(Case::Kebab) { if repo_id.is_empty() || repo_id != repo_id.to_case(Case::Kebab) {
return Err(N34Error::InvalidRepoId); return Err(N34Error::InvalidRepoId);
} }

View File

@@ -75,3 +75,8 @@ pub fn event_into_repo(event: Event, repo_id: impl Into<String>) -> GitRepositor
maintainers: tags.dmap_tag(TagKind::Maintainers, tag_values), 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()
}