upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib/repo_ref.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-03 15:29:06 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-03 15:29:06 +0000
commitd2478dbca6c5d3f61331ceabe20c6d9315cd6840 (patch)
tree9cd79f52ac96378ef68b4798db48ee65839d9f74 /src/lib/repo_ref.rs
parent79f55ad6488ddb628438580acf54a1d23a990cb3 (diff)
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.
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs23
1 files changed, 16 insertions, 7 deletions
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 {
188 /// coordinates without relay hints 188 /// coordinates without relay hints
189 pub fn coordinates(&self) -> HashSet<Coordinate> { 189 pub fn coordinates(&self) -> HashSet<Coordinate> {
190 let mut res = HashSet::new(); 190 let mut res = HashSet::new();
191 res.insert(Coordinate {
192 kind: Kind::GitRepoAnnouncement,
193 public_key: self.trusted_maintainer,
194 identifier: self.identifier.clone(),
195 relays: vec![],
196 });
197
191 for m in &self.maintainers { 198 for m in &self.maintainers {
192 res.insert(Coordinate { 199 res.insert(Coordinate {
193 kind: Kind::GitRepoAnnouncement, 200 kind: Kind::GitRepoAnnouncement,
@@ -226,7 +233,7 @@ impl RepoRef {
226 "{}", 233 "{}",
227 NostrUrlDecoded { 234 NostrUrlDecoded {
228 original_string: String::new(), 235 original_string: String::new(),
229 coordinates: HashSet::from_iter(vec![self.coordinate_with_hint()]), 236 coordinate: self.coordinate_with_hint(),
230 protocol: None, 237 protocol: None,
231 user: None, 238 user: None,
232 } 239 }
@@ -238,7 +245,7 @@ pub async fn get_repo_coordinates(
238 git_repo: &Repo, 245 git_repo: &Repo,
239 #[cfg(test)] client: &crate::client::MockConnect, 246 #[cfg(test)] client: &crate::client::MockConnect,
240 #[cfg(not(test))] client: &Client, 247 #[cfg(not(test))] client: &Client,
241) -> Result<HashSet<Coordinate>> { 248) -> Result<Coordinate> {
242 try_and_get_repo_coordinates(git_repo, client, true).await 249 try_and_get_repo_coordinates(git_repo, client, true).await
243} 250}
244 251
@@ -247,7 +254,7 @@ pub async fn try_and_get_repo_coordinates(
247 #[cfg(test)] client: &crate::client::MockConnect, 254 #[cfg(test)] client: &crate::client::MockConnect,
248 #[cfg(not(test))] client: &Client, 255 #[cfg(not(test))] client: &Client,
249 prompt_user: bool, 256 prompt_user: bool,
250) -> Result<HashSet<Coordinate>> { 257) -> Result<Coordinate> {
251 let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?; 258 let mut repo_coordinates = get_repo_coordinates_from_git_config(git_repo)?;
252 259
253 if repo_coordinates.is_empty() { 260 if repo_coordinates.is_empty() {
@@ -265,7 +272,11 @@ pub async fn try_and_get_repo_coordinates(
265 bail!("couldn't find repo coordinates in git config nostr.repo or in maintainers.yaml"); 272 bail!("couldn't find repo coordinates in git config nostr.repo or in maintainers.yaml");
266 } 273 }
267 } 274 }
268 Ok(repo_coordinates) 275 Ok(repo_coordinates
276 .iter()
277 .next()
278 .context("would have bailed if no coordinates found")?
279 .clone())
269} 280}
270 281
271fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result<HashSet<Coordinate>> { 282fn get_repo_coordinates_from_git_config(git_repo: &Repo) -> Result<HashSet<Coordinate>> {
@@ -285,9 +296,7 @@ fn get_repo_coordinates_from_nostr_remotes(git_repo: &Repo) -> Result<HashSet<Co
285 for remote_name in git_repo.git_repo.remotes()?.iter().flatten() { 296 for remote_name in git_repo.git_repo.remotes()?.iter().flatten() {
286 if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() { 297 if let Some(remote_url) = git_repo.git_repo.find_remote(remote_name)?.url() {
287 if let Ok(nostr_url_decoded) = NostrUrlDecoded::from_str(remote_url) { 298 if let Ok(nostr_url_decoded) = NostrUrlDecoded::from_str(remote_url) {
288 for c in nostr_url_decoded.coordinates { 299 repo_coordinates.insert(nostr_url_decoded.coordinate);
289 repo_coordinates.insert(c);
290 }
291 } 300 }
292 } 301 }
293 } 302 }