feat: Add repo announce command

Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-05 19:55:53 +00:00
parent 273058fe3f
commit b444aeba0a
4 changed files with 167 additions and 1 deletions

View File

@@ -14,7 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://gnu.org/licenses/gpl-3.0.html>.
use nostr::event::{TagKind, TagStandard, Tags};
use convert_case::{Case, Casing};
use nostr::{
event::{EventBuilder, Tag, TagKind, TagStandard, Tags},
key::PublicKey,
nips::nip34::GitRepositoryAnnouncement,
types::{RelayUrl, Url},
};
use crate::error::{N34Error, N34Result};
/// A trait to add helper instance function to [`Tags`] type
@@ -47,3 +55,39 @@ impl Tags {
.map(f)
}
}
/// Trait for building [`GitRepositoryAnnouncement`] events
#[easy_ext::ext(NewGitRepositoryAnnouncement)]
impl EventBuilder {
/// Creates a new [`GitRepositoryAnnouncement`] event builder with the given
/// repository details.
#[allow(clippy::too_many_arguments)]
pub fn new_git_repo(
repo_id: String,
name: Option<String>,
description: Option<String>,
web: Vec<Url>,
clone: Vec<Url>,
relays: Vec<RelayUrl>,
maintainers: Vec<PublicKey>,
labels: Vec<String>,
) -> N34Result<EventBuilder> {
if repo_id.is_empty() || repo_id != repo_id.to_case(Case::Kebab) {
return Err(N34Error::InvalidRepoId);
}
Ok(
EventBuilder::git_repository_announcement(GitRepositoryAnnouncement {
id: repo_id.to_owned(),
name,
description,
web,
clone,
relays,
euc: None,
maintainers,
})?
.tags(labels.into_iter().map(Tag::hashtag)),
)
}
}