refactor: Support more than one naddr instead of one

This commit supports multiple naddrs for sending issues to and searching
for repositories by extracting the embedded relays, and appending to the
address file instead of overwriting its previous contents. A header has
also been added to the `nostr-address` file to clarify its purpose.

This enhancement accommodates maintainers who distribute issue tracking
across multiple repositories, preventing confusion if the primary
maintainer steps down. Now, issues and patches will reference all
relevant repositories, not just one.

Note that repositories won't automatically include all maintainers'
addresses unless explicitly specified. Maintainers may manage a
repository under a project-specific public key rather than individual
keys. Addresses are only added to issues and patches when explicitly
provided via the command or written to the address file. This prevents
unintended inclusions and ensures clarity.

Suggested-by: DanConwayDev <DanConwayDev@protonmail.com>
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
Awiteb
2025-05-27 06:42:05 +00:00
parent 87da5035da
commit 37cf601c01
8 changed files with 272 additions and 113 deletions

View File

@@ -195,20 +195,27 @@ impl NostrClient {
.first_owned())
}
/// Try to fetch a repository and returns it
pub async fn fetch_repo(
/// Try to fetch the reposotoies and returns them
pub async fn fetch_repos(
&self,
repo_naddr: &Coordinate,
) -> N34Result<GitRepositoryAnnouncement> {
let filter = Filter::new()
.author(repo_naddr.public_key)
.kind(Kind::GitRepoAnnouncement)
.identifier(&repo_naddr.identifier);
self.fetch_event(filter)
.await?
.map(|e| utils::event_into_repo(e, &repo_naddr.identifier))
.ok_or(N34Error::NotFoundRepo)
repo_naddrs: &[Coordinate],
) -> N34Result<Vec<GitRepositoryAnnouncement>> {
future::join_all(repo_naddrs.iter().map(|c| {
async {
self.fetch_event(
Filter::new()
.author(c.public_key)
.identifier(&c.identifier)
.kind(Kind::GitRepoAnnouncement),
)
.await?
.map(|e| utils::event_into_repo(e, &c.identifier))
.ok_or(N34Error::NotFoundRepo)
}
}))
.await
.into_iter()
.collect()
}
/// Finds the root issue or patch for a given event. If the event is already

View File

@@ -20,6 +20,7 @@ use nostr::{
key::PublicKey,
nips::{
nip01::Coordinate,
nip19::Nip19Coordinate,
nip21::Nip21,
nip34::{GitIssue, GitRepositoryAnnouncement},
},
@@ -164,3 +165,26 @@ impl Token<'_> {
}
}
}
/// Utility functions for working with lists of NIP-19 coordinates
#[easy_ext::ext(NaddrsUtils)]
impl Vec<Nip19Coordinate> {
/// Converts these coordinate addresses to basic coordinates
pub fn into_coordinates(self) -> Vec<Coordinate> {
self.into_iter().map(|n| n.coordinate).collect()
}
/// Extracts all relay URLs from these coordinates
pub fn extract_relays(&self) -> Vec<RelayUrl> {
self.iter().flat_map(|n| n.relays.clone()).collect()
}
}
/// Utility functions for working with lists of repository announcement
#[easy_ext::ext(ReposUtils)]
impl Vec<GitRepositoryAnnouncement> {
/// Extracts all relay URLs from these reposotoies
pub fn extract_relays(&self) -> Vec<RelayUrl> {
self.iter().flat_map(|n| n.relays.clone()).collect()
}
}

View File

@@ -220,21 +220,12 @@ pub fn nostr_address_path() -> std::io::Result<PathBuf> {
/// If the given coordinate is Some, return it. Otherwise, try to read and parse
/// the first non-comment line from the `nostr-address` file.
pub fn naddr_or_file(
naddr: Option<Nip19Coordinate>,
pub fn naddrs_or_file(
naddrs: Option<Vec<Nip19Coordinate>>,
address_file_path: &Path,
) -> N34Result<Nip19Coordinate> {
if let Some(naddr) = naddr {
return Ok(naddr);
) -> N34Result<Vec<Nip19Coordinate>> {
if let Some(naddrs) = naddrs {
return Ok(naddrs);
}
parsers::repo_naddr(
fs::read_to_string(address_file_path)
.map_err(N34Error::CanNotReadNostrAddressFile)?
.split("\n")
.find(|line| !line.starts_with("#") && !line.trim().is_empty())
.ok_or(N34Error::EmptyNostrAddressFile)?
.trim(),
)
.map_err(N34Error::InvalidNostrAddressFileContent)
parsers::parse_nostr_address_file(address_file_path)
}