Skip to content

Commit

Permalink
feat(repo_ref): find coordinates from git remotes
Browse files Browse the repository at this point in the history
unless nostr.repo git config is set look for coodinates in git
remotes that use the nostr format
  • Loading branch information
DanConwayDev committed Aug 19, 2024
1 parent c66e6b4 commit 42b0bad
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/repo_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -229,8 +229,9 @@ pub async fn try_and_get_repo_coordinates(
) -> Result<HashSet<Coordinate>> {
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?;
Expand Down Expand Up @@ -258,6 +259,20 @@ fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result<HashSet<Coord
Ok(repo_coordinates)
}

fn get_repo_coordinates_from_nostr_remotes(git_repo: &Repo) -> Result<HashSet<Coordinate>> {
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,
Expand Down

0 comments on commit 42b0bad

Please sign in to comment.