From d2478dbca6c5d3f61331ceabe20c6d9315cd6840 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 3 Dec 2024 15:29:06 +0000 Subject: refactor: limit fetch to 1 trusted coordinate previously fetch supported fetching multiple trusted coordinates at once. The additional complexity trade off isn't worth it. It will still fetch events related to the coordinates of maintainers that the trusted maintainer lists. A scenario where there might be multiple trusted coordinates is where a large repo is split into multiple nostr repos to manage pull requests and issues in seperate sub-units. I might therefore have different remotes that target different identifiers. There also might be different set of maintainers groups that are have different views on the latest state of the same codebase and they haven't split off into using different identifiers. Its simplier ngit to fetch these different nostr repos independantly when requested. git-remote-nostr will do this automatically as it works through remotes but for ngit cmds a further change is required so `get_repo_coordinates` and `try_and_get_repo_coordinates` prompts to select the desired one. --- src/bin/git_remote_nostr/main.rs | 12 ++++-- src/bin/ngit/sub_commands/init.rs | 66 +++++++++++------------------- src/lib/client.rs | 86 +++++++++++++++++++++++---------------- src/lib/git/nostr_url.rs | 72 ++++++++++++++++---------------- src/lib/login/user.rs | 6 +-- src/lib/repo_ref.rs | 23 +++++++---- 6 files changed, 134 insertions(+), 131 deletions(-) (limited to 'src') diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 54fb7cf..8e12d68 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -43,10 +43,10 @@ async fn main() -> Result<()> { client.set_signer(signer).await; } - fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinates).await?; + fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinate).await?; let repo_ref = - get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinates).await?; + get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinate).await?; let stdin = io::stdin(); let mut line = String::new(); @@ -148,12 +148,16 @@ fn process_args() -> Result> { async fn fetching_with_report_for_helper( git_repo_path: &Path, client: &Client, - repo_coordinates: &HashSet, + trusted_maintainer_coordinate: &Coordinate, ) -> Result<()> { let term = console::Term::stderr(); term.write_line("nostr: fetching...")?; let (relay_reports, progress_reporter) = client - .fetch_all(Some(git_repo_path), repo_coordinates, &HashSet::new()) + .fetch_all( + Some(git_repo_path), + Some(trusted_maintainer_coordinate), + &HashSet::new(), + ) .await?; if !relay_reports.iter().any(std::result::Result::is_err) { let _ = progress_reporter.clear(); diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index bf57769..9d87ba2 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -60,18 +60,17 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { let mut client = Client::default(); - let repo_coordinates = if let Ok(repo_coordinates) = + let repo_coordinate = if let Ok(repo_coordinate) = try_and_get_repo_coordinates(&git_repo, &client, false).await { - Some(repo_coordinates) + Some(repo_coordinate) } else { None }; - let repo_ref = if let Some(repo_coordinates) = repo_coordinates.clone() { - fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; - if let Ok(repo_ref) = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await - { + let repo_ref = if let Some(repo_coordinate) = &repo_coordinate { + fetching_with_report(git_repo_path, &client, repo_coordinate).await?; + if let Ok(repo_ref) = get_repo_ref_from_cache(Some(git_repo_path), repo_coordinate).await { Some(repo_ref) } else { None @@ -98,12 +97,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { .with_prompt("repo name") .with_default(if let Some(repo_ref) = &repo_ref { repo_ref.name.clone() - } else if let Some(repo_coordinates) = repo_coordinates.clone() { - if let Some(coordinate) = repo_coordinates.iter().next() { - coordinate.identifier.clone() - } else { - String::new() - } + } else if let Some(coordinate) = &repo_coordinate { + coordinate.identifier.clone() } else { String::new() }), @@ -119,12 +114,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { ) .with_default(if let Some(repo_ref) = &repo_ref { repo_ref.identifier.clone() - } else if let Some(repo_coordinates) = repo_coordinates.clone() { - if let Some(coordinate) = repo_coordinates.iter().next() { - coordinate.identifier.clone() - } else { - String::new() - } + } else if let Some(repo_coordinate) = &repo_coordinate { + repo_coordinate.identifier.clone() } else { let fallback = name .clone() @@ -503,32 +494,21 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { if let Some(origin_url) = origin_remote.url() { if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { - if let Some(c) = &nostr_url.coordinates.iter().next() { - if c.identifier == repo_ref.identifier { - if nostr_url - .coordinates - .iter() - .next() - .context( - "a decoded nostr url will always have at least one coordinate", - )? - .public_key - == repo_ref.trusted_maintainer - { - return Ok(()); - } - // origin is set to a different trusted maintainer - println!( - "warning: currently git remote 'origin' is set to a different trusted maintainer with the same identifier" - ); - ask_to_set_origin_remote(repo_ref, git_repo)?; - } else { - // origin is linked to a different identifier - println!( - "warning: currently git remote 'origin' is set to a different repository identifier" - ); - ask_to_set_origin_remote(repo_ref, git_repo)?; + if nostr_url.coordinate.identifier == repo_ref.identifier { + if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer { + return Ok(()); } + // origin is set to a different trusted maintainer + println!( + "warning: currently git remote 'origin' is set to a different trusted maintainer with the same identifier" + ); + ask_to_set_origin_remote(repo_ref, git_repo)?; + } else { + // origin is linked to a different identifier + println!( + "warning: currently git remote 'origin' is set to a different repository identifier" + ); + ask_to_set_origin_remote(repo_ref, git_repo)?; } } else { // remote is non-nostr url diff --git a/src/lib/client.rs b/src/lib/client.rs index 4b87cd8..32f5bd7 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -89,7 +89,7 @@ pub trait Connect { async fn fetch_all<'a>( &self, git_repo_path: Option<&'a Path>, - repo_coordinates: &HashSet, + repo_coordinates: Option<&'a Coordinate>, user_profiles: &HashSet, ) -> Result<(Vec>, MultiProgress)>; async fn fetch_all_from_relay<'a>( @@ -329,7 +329,7 @@ impl Connect for Client { async fn fetch_all<'a>( &self, git_repo_path: Option<&'a Path>, - repo_coordinates: &HashSet, + trusted_maintainer_coordinate: Option<&'a Coordinate>, user_profiles: &HashSet, ) -> Result<(Vec>, MultiProgress)> { let fallback_relays = &self @@ -340,7 +340,7 @@ impl Connect for Client { let mut request = create_relays_request( git_repo_path, - repo_coordinates, + trusted_maintainer_coordinate, user_profiles, fallback_relays.clone(), ) @@ -468,8 +468,12 @@ impl Connect for Client { } processed_relays.extend(relays.clone()); - if let Ok(repo_ref) = get_repo_ref_from_cache(git_repo_path, repo_coordinates).await { - request.repo_relays = repo_ref.relays.iter().cloned().collect(); + if let Some(trusted_maintainer_coordinate) = trusted_maintainer_coordinate { + if let Ok(repo_ref) = + get_repo_ref_from_cache(git_repo_path, trusted_maintainer_coordinate).await + { + request.repo_relays = repo_ref.relays.iter().cloned().collect(); + } } request.user_relays_for_profiles = { @@ -809,18 +813,24 @@ pub async fn save_event_in_global_cache( pub async fn get_repo_ref_from_cache( git_repo_path: Option<&Path>, - repo_coordinates: &HashSet, + repo_coordinate: &Coordinate, ) -> Result { let mut maintainers = HashSet::new(); let mut new_coordinate: bool; - for c in repo_coordinates { - maintainers.insert(c.public_key); - } + maintainers.insert(repo_coordinate.public_key); let mut repo_events = vec![]; loop { new_coordinate = false; - let repo_events_filter = get_filter_repo_events(repo_coordinates); + let repo_events_filter = + get_filter_repo_events(&HashSet::from_iter(maintainers.iter().map(|m| { + Coordinate { + kind: Kind::GitRepoAnnouncement, + public_key: *m, + identifier: repo_coordinate.identifier.to_string(), + relays: vec![], + } + }))); let events = [ get_event_from_global_cache(git_repo_path, vec![repo_events_filter.clone()]).await?, @@ -832,13 +842,7 @@ pub async fn get_repo_ref_from_cache( ] .concat(); for e in events { - if let Ok(repo_ref) = RepoRef::try_from(( - e.clone(), - repo_coordinates - .iter() - .next() - .map(|coordinate| coordinate.public_key), - )) { + if let Ok(repo_ref) = RepoRef::try_from((e.clone(), None)) { for m in repo_ref.maintainers { if maintainers.insert(m) { new_coordinate = true; @@ -857,10 +861,7 @@ pub async fn get_repo_ref_from_cache( .first() .context("no repo announcement event found at specified coordinates. if you are the repository maintainer consider running `ngit init` to create one")? .clone(), - repo_coordinates - .iter() - .next() - .map(|coordinate| coordinate.public_key), + Some(repo_coordinate.public_key), ))?; let mut events: HashMap = HashMap::new(); @@ -913,27 +914,40 @@ pub async fn get_state_from_cache( #[allow(clippy::too_many_lines)] async fn create_relays_request( git_repo_path: Option<&Path>, - repo_coordinates: &HashSet, + trusted_maintainer_coordinate: Option<&Coordinate>, user_profiles: &HashSet, fallback_relays: HashSet, ) -> Result { - let repo_ref = get_repo_ref_from_cache(git_repo_path, repo_coordinates).await; + let repo_ref = if let Some(trusted_maintainer_coordinate) = trusted_maintainer_coordinate { + if let Ok(repo_ref) = + get_repo_ref_from_cache(git_repo_path, trusted_maintainer_coordinate).await + { + Some(repo_ref) + } else { + None + } + } else { + None + }; let repo_coordinates = { // add coordinates of users listed in maintainers to explicitly specified // coodinates - let mut repo_coordinates = repo_coordinates.clone(); - if let Ok(repo_ref) = &repo_ref { + let mut set: HashSet = HashSet::new(); + if let Some(trusted_maintainer_coordinate) = trusted_maintainer_coordinate { + set.insert(trusted_maintainer_coordinate.clone()); + } + if let Some(repo_ref) = &repo_ref { for c in repo_ref.coordinates() { - if !repo_coordinates + if !set .iter() .any(|e| e.identifier.eq(&c.identifier) && e.public_key.eq(&c.public_key)) { - repo_coordinates.insert(c); + set.insert(c); } } } - repo_coordinates + set }; let repo_coordinates_without_relays = { @@ -954,7 +968,7 @@ async fn create_relays_request( let mut contributors: HashSet = HashSet::new(); if !repo_coordinates_without_relays.is_empty() { - if let Ok(repo_ref) = &repo_ref { + if let Some(repo_ref) = &repo_ref { for m in &repo_ref.maintainers { contributors.insert(m.to_owned()); } @@ -1077,7 +1091,7 @@ async fn create_relays_request( let relays = { let mut relays = fallback_relays; - if let Ok(repo_ref) = &repo_ref { + if let Some(repo_ref) = &repo_ref { for r in repo_ref.relays.clone() { relays.insert(r); } @@ -1113,7 +1127,7 @@ async fn create_relays_request( selected_relay: None, repo_relays: relays, relay_column_width, - repo_coordinates_without_relays: if let Ok(repo_ref) = &repo_ref { + repo_coordinates_without_relays: if let Some(repo_ref) = &repo_ref { repo_ref.coordinates_with_timestamps() } else { repo_coordinates_without_relays @@ -1121,7 +1135,7 @@ async fn create_relays_request( .map(|c| (c.clone(), None)) .collect() }, - state: if let Ok(repo_ref) = &repo_ref { + state: if let Some(repo_ref) = &repo_ref { if let Ok(existing_state) = get_state_from_cache(git_repo_path, repo_ref).await { Some((existing_state.event.created_at, existing_state.event.id)) } else { @@ -1523,12 +1537,16 @@ pub async fn fetching_with_report( git_repo_path: &Path, #[cfg(test)] client: &crate::client::MockConnect, #[cfg(not(test))] client: &Client, - repo_coordinates: &HashSet, + trusted_maintainer_coordinate: &Coordinate, ) -> Result { let term = console::Term::stderr(); term.write_line("fetching updates...")?; let (relay_reports, progress_reporter) = client - .fetch_all(Some(git_repo_path), repo_coordinates, &HashSet::new()) + .fetch_all( + Some(git_repo_path), + Some(trusted_maintainer_coordinate), + &HashSet::new(), + ) .await?; if !relay_reports.iter().any(std::result::Result::is_err) { let _ = progress_reporter.clear(); diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index a501765..c26bb2e 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -1,5 +1,5 @@ use core::fmt; -use std::{collections::HashSet, str::FromStr}; +use std::str::FromStr; use anyhow::{anyhow, bail, Context, Error, Result}; use nostr::nips::nip01::Coordinate; @@ -56,7 +56,7 @@ impl FromStr for ServerProtocol { #[derive(Debug, PartialEq)] pub struct NostrUrlDecoded { pub original_string: String, - pub coordinates: HashSet, + pub coordinate: Coordinate, pub protocol: Option, pub user: Option, } @@ -70,9 +70,8 @@ impl fmt::Display for NostrUrlDecoded { if let Some(protocol) = &self.protocol { write!(f, "{}/", protocol)?; } - let c = self.coordinates.iter().next().unwrap(); - write!(f, "{}/", c.public_key.to_bech32().unwrap())?; - if let Some(relay) = c.relays.first() { + write!(f, "{}/", self.coordinate.public_key.to_bech32().unwrap())?; + if let Some(relay) = self.coordinate.relays.first() { write!( f, "{}/", @@ -84,7 +83,7 @@ impl fmt::Display for NostrUrlDecoded { ) )?; } - write!(f, "{}", c.identifier) + write!(f, "{}", self.coordinate.identifier) } } @@ -94,7 +93,6 @@ impl std::str::FromStr for NostrUrlDecoded { type Err = anyhow::Error; fn from_str(url: &str) -> Result { - let mut coordinates = HashSet::new(); let mut protocol = None; let mut user = None; let mut relays = vec![]; @@ -157,9 +155,9 @@ impl std::str::FromStr for NostrUrlDecoded { // extract naddr npub//identifer let part = parts.first().context(INCORRECT_NOSTR_URL_FORMAT_ERROR)?; // naddr used - if let Ok(coordinate) = Coordinate::parse(part) { + let coordinate = if let Ok(coordinate) = Coordinate::parse(part) { if coordinate.kind.eq(&nostr_sdk::Kind::GitRepoAnnouncement) { - coordinates.insert(coordinate); + coordinate } else { bail!("naddr doesnt point to a git repository announcement"); } @@ -181,19 +179,19 @@ impl std::str::FromStr for NostrUrlDecoded { RelayUrl::parse(&decoded).context("could not parse relays in nostr git url")?; relays.push(url); } - coordinates.insert(Coordinate { + Coordinate { identifier, public_key, kind: nostr_sdk::Kind::GitRepoAnnouncement, relays, - }); + } } else { bail!(INCORRECT_NOSTR_URL_FORMAT_ERROR); - } + }; Ok(Self { original_string: url.to_string(), - coordinates, + coordinate, protocol, user, }) @@ -865,8 +863,6 @@ mod tests { } } mod nostr_git_url_format { - use std::collections::HashSet; - use nostr::nips::nip01::Coordinate; use nostr_sdk::PublicKey; @@ -880,7 +876,7 @@ mod tests { "{}", NostrUrlDecoded { original_string: String::new(), - coordinates: HashSet::from_iter(vec![Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -888,7 +884,7 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }]), + }, protocol: None, user: None, } @@ -905,7 +901,7 @@ mod tests { "{}", NostrUrlDecoded { original_string: String::new(), - coordinates: HashSet::from_iter(vec![Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -913,7 +909,7 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![], - }]), + }, protocol: None, user: None, } @@ -930,7 +926,7 @@ mod tests { "{}", NostrUrlDecoded { original_string: String::new(), - coordinates: HashSet::from_iter(vec![Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -938,7 +934,7 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }]), + }, protocol: Some(ServerProtocol::Ssh), user: None, } @@ -955,7 +951,7 @@ mod tests { "{}", NostrUrlDecoded { original_string: String::new(), - coordinates: HashSet::from_iter(vec![Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -963,7 +959,7 @@ mod tests { .unwrap(), kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }]), + }, protocol: Some(ServerProtocol::Ssh), user: Some("bla".to_string()), } @@ -1002,7 +998,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -1011,7 +1007,7 @@ mod tests { kind: nostr_sdk::Kind::GitRepoAnnouncement, relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], /* wont add the * slash */ - }]), + }, protocol: None, user: None, }, @@ -1031,7 +1027,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(false)]), + coordinate: get_model_coordinate(false), protocol: None, user: None, }, @@ -1049,7 +1045,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(true)]), + coordinate: get_model_coordinate(true), protocol: None, user: None, }, @@ -1067,7 +1063,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(true)]), + coordinate: get_model_coordinate(true), protocol: None, user: None, }, @@ -1086,7 +1082,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -1097,7 +1093,7 @@ mod tests { RelayUrl::parse("wss://nos.lol/").unwrap(), RelayUrl::parse("wss://relay.damus.io/").unwrap(), ], - }]), + }, protocol: None, user: None, }, @@ -1112,7 +1108,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(false)]), + coordinate: get_model_coordinate(false), protocol: Some(ServerProtocol::Ssh), user: None, }, @@ -1127,7 +1123,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(false)]), + coordinate: get_model_coordinate(false), protocol: Some(ServerProtocol::Ssh), user: Some("fred".to_string()), }, @@ -1146,7 +1142,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(true)]), + coordinate: get_model_coordinate(true), protocol: None, user: None, }, @@ -1164,7 +1160,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(true)]), + coordinate: get_model_coordinate(true), protocol: None, user: None, }, @@ -1183,7 +1179,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([Coordinate { + coordinate: Coordinate { identifier: "ngit".to_string(), public_key: PublicKey::parse( "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", @@ -1194,7 +1190,7 @@ mod tests { RelayUrl::parse("wss://nos.lol/").unwrap(), RelayUrl::parse("wss://relay.damus.io/").unwrap(), ], - }]), + }, protocol: None, user: None, }, @@ -1209,7 +1205,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(false)]), + coordinate: get_model_coordinate(false), protocol: Some(ServerProtocol::Ssh), user: None, }, @@ -1224,7 +1220,7 @@ mod tests { NostrUrlDecoded::from_str(&url)?, NostrUrlDecoded { original_string: url.clone(), - coordinates: HashSet::from([get_model_coordinate(false)]), + coordinate: get_model_coordinate(false), protocol: Some(ServerProtocol::Ssh), user: Some("fred".to_string()), }, diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs index 9534bbe..1898a1f 100644 --- a/src/lib/login/user.rs +++ b/src/lib/login/user.rs @@ -75,11 +75,7 @@ pub async fn get_user_details( let term = console::Term::stderr(); term.write_line("searching for profile...")?; let (_, progress_reporter) = client - .fetch_all( - git_repo_path, - &HashSet::new(), - &HashSet::from_iter(vec![*public_key]), - ) + .fetch_all(git_repo_path, None, &HashSet::from_iter(vec![*public_key])) .await?; if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { progress_reporter.clear()?; diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 69fbe64..988c87d 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -188,6 +188,13 @@ impl RepoRef { /// coordinates without relay hints pub fn coordinates(&self) -> HashSet { let mut res = HashSet::new(); + res.insert(Coordinate { + kind: Kind::GitRepoAnnouncement, + public_key: self.trusted_maintainer, + identifier: self.identifier.clone(), + relays: vec![], + }); + for m in &self.maintainers { res.insert(Coordinate { kind: Kind::GitRepoAnnouncement, @@ -226,7 +233,7 @@ impl RepoRef { "{}", NostrUrlDecoded { original_string: String::new(), - coordinates: HashSet::from_iter(vec![self.coordinate_with_hint()]), + coordinate: self.coordinate_with_hint(), protocol: None, user: None, } @@ -238,7 +245,7 @@ pub async fn get_repo_coordinates( git_repo: &Repo, #[cfg(test)] client: &crate::client::MockConnect, #[cfg(not(test))] client: &Client, -) -> Result> { +) -> Result { try_and_get_repo_coordinates(git_repo, client, true).await } @@ -247,7 +254,7 @@ pub async fn try_and_get_repo_coordinates( #[cfg(test)] client: &crate::client::MockConnect, #[cfg(not(test))] client: &Client, prompt_user: bool, -) -> Result> { +) -> Result { let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?; if repo_coordinates.is_empty() { @@ -265,7 +272,11 @@ pub async fn try_and_get_repo_coordinates( bail!("couldn't find repo coordinates in git config nostr.repo or in maintainers.yaml"); } } - Ok(repo_coordinates) + Ok(repo_coordinates + .iter() + .next() + .context("would have bailed if no coordinates found")? + .clone()) } fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result> { @@ -285,9 +296,7 @@ fn get_repo_coordinates_from_nostr_remotes(git_repo: &Repo) -> Result