From 42b0bad048b64ef51f45da6a6988823e5a49da1d Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 19 Aug 2024 08:54:16 +0100 Subject: feat(repo_ref): find coordinates from git remotes unless nostr.repo git config is set look for coodinates in git remotes that use the nostr format --- src/repo_ref.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/repo_ref.rs b/src/repo_ref.rs index fa8ff4e..94af864 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs @@ -16,7 +16,7 @@ use crate::client::Client; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, client::{get_event_from_global_cache, get_events_from_cache, sign_event, Connect}, - git::{Repo, RepoActions}, + git::{nostr_git_url_to_repo_coordinates, Repo, RepoActions}, }; #[derive(Default)] @@ -229,8 +229,9 @@ pub async fn try_and_get_repo_coordinates( ) -> Result> { let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?; - // TODO: when nostr remotes functionality is added, iterate on each remote and - // extract coordinates + if repo_coordinates.is_empty() { + repo_coordinates = get_repo_coordinates_from_nostr_remotes(git_repo)?; + } if repo_coordinates.is_empty() { repo_coordinates = get_repo_coordinates_from_maintainers_yaml(git_repo, client).await?; @@ -258,6 +259,20 @@ fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result Result> { + let mut repo_coordinates = HashSet::new(); + for remote_name in git_repo.git_repo.remotes()?.iter().flatten() { + if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() { + if let Ok(coordinates) = nostr_git_url_to_repo_coordinates(remote_url) { + for c in coordinates { + repo_coordinates.insert(c); + } + } + } + } + Ok(repo_coordinates) +} + async fn get_repo_coordinates_from_maintainers_yaml( git_repo: &Repo, #[cfg(test)] client: &crate::client::MockConnect, -- cgit v1.2.3