diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-19 08:54:16 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-08-19 08:54:16 +0100 |
| commit | 42b0bad048b64ef51f45da6a6988823e5a49da1d (patch) | |
| tree | 0c12cd9c5b2e8d0c6cf6eb82703b38f9ed84c1a5 /src | |
| parent | c66e6b4e1bc828953ed964938cedc03040197716 (diff) | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/repo_ref.rs | 21 |
1 files changed, 18 insertions, 3 deletions
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; | |||
| 16 | use crate::{ | 16 | use crate::{ |
| 17 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, | 17 | cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, |
| 18 | client::{get_event_from_global_cache, get_events_from_cache, sign_event, Connect}, | 18 | client::{get_event_from_global_cache, get_events_from_cache, sign_event, Connect}, |
| 19 | git::{Repo, RepoActions}, | 19 | git::{nostr_git_url_to_repo_coordinates, Repo, RepoActions}, |
| 20 | }; | 20 | }; |
| 21 | 21 | ||
| 22 | #[derive(Default)] | 22 | #[derive(Default)] |
| @@ -229,8 +229,9 @@ pub async fn try_and_get_repo_coordinates( | |||
| 229 | ) -> Result<HashSet<Coordinate>> { | 229 | ) -> Result<HashSet<Coordinate>> { |
| 230 | let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?; | 230 | let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?; |
| 231 | 231 | ||
| 232 | // TODO: when nostr remotes functionality is added, iterate on each remote and | 232 | if repo_coordinates.is_empty() { |
| 233 | // extract coordinates | 233 | repo_coordinates = get_repo_coordinates_from_nostr_remotes(git_repo)?; |
| 234 | } | ||
| 234 | 235 | ||
| 235 | if repo_coordinates.is_empty() { | 236 | if repo_coordinates.is_empty() { |
| 236 | repo_coordinates = get_repo_coordinates_from_maintainers_yaml(git_repo, client).await?; | 237 | 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<HashSet<Coord | |||
| 258 | Ok(repo_coordinates) | 259 | Ok(repo_coordinates) |
| 259 | } | 260 | } |
| 260 | 261 | ||
| 262 | fn get_repo_coordinates_from_nostr_remotes(git_repo: &Repo) -> Result<HashSet<Coordinate>> { | ||
| 263 | let mut repo_coordinates = HashSet::new(); | ||
| 264 | for remote_name in git_repo.git_repo.remotes()?.iter().flatten() { | ||
| 265 | if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() { | ||
| 266 | if let Ok(coordinates) = nostr_git_url_to_repo_coordinates(remote_url) { | ||
| 267 | for c in coordinates { | ||
| 268 | repo_coordinates.insert(c); | ||
| 269 | } | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } | ||
| 273 | Ok(repo_coordinates) | ||
| 274 | } | ||
| 275 | |||
| 261 | async fn get_repo_coordinates_from_maintainers_yaml( | 276 | async fn get_repo_coordinates_from_maintainers_yaml( |
| 262 | git_repo: &Repo, | 277 | git_repo: &Repo, |
| 263 | #[cfg(test)] client: &crate::client::MockConnect, | 278 | #[cfg(test)] client: &crate::client::MockConnect, |