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>2025-06-19 16:38:58 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-06-19 16:38:58 +0100
commitd1a6d62e895acd329cb6bae51eb88eb9f290b0a4 (patch)
treec4455844fc2e2173e6dd2bb61bcf86d0bb407a90 /src/lib/repo_ref.rs
parent3598a05b98852baeb324bdaa00cb69035157f636 (diff)
refactor: rename ngit_relay to grasp
in function, params and variable names
Diffstat (limited to 'src/lib/repo_ref.rs')
-rw-r--r--src/lib/repo_ref.rs41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index 78968b4..c1fc288 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -308,8 +308,8 @@ impl RepoRef {
308 } 308 }
309 } 309 }
310 310
311 pub fn ngit_relays(&self) -> Vec<String> { 311 pub fn grasp_servers(&self) -> Vec<String> {
312 detect_existing_ngit_relays(Some(self), &[], &[], &[], &self.identifier) 312 detect_existing_grasp_servers(Some(self), &[], &[], &[], &self.identifier)
313 } 313 }
314} 314}
315 315
@@ -586,7 +586,7 @@ pub fn save_repo_config_to_yaml(
586 .context("failed to write maintainers to maintainers.yaml file serde_yaml") 586 .context("failed to write maintainers to maintainers.yaml file serde_yaml")
587} 587}
588 588
589pub fn detect_existing_ngit_relays( 589pub fn detect_existing_grasp_servers(
590 repo_ref: Option<&RepoRef>, 590 repo_ref: Option<&RepoRef>,
591 args_relays: &[String], 591 args_relays: &[String],
592 args_clone_url: &[String], 592 args_clone_url: &[String],
@@ -626,45 +626,46 @@ pub fn detect_existing_ngit_relays(
626 Vec::new() 626 Vec::new()
627 }; 627 };
628 628
629 let mut existing_ngit_relays = Vec::new(); 629 let mut existing_grasp_servers = Vec::new();
630 for url in &clone_urls { 630 for url in &clone_urls {
631 let Ok(formatted_as_ngit_relay_url) = normalize_ngit_relay_url(url) else { 631 let Ok(formatted_as_grasp_server_url) = normalize_grasp_server_url(url) else {
632 continue; 632 continue;
633 }; 633 };
634 if existing_ngit_relays.contains(&formatted_as_ngit_relay_url) { 634 if existing_grasp_servers.contains(&formatted_as_grasp_server_url) {
635 continue; 635 continue;
636 } 636 }
637 637
638 let clone_url_is_ngit_relay_format = if let Ok(npub) = extract_npub(url) { 638 let clone_url_is_grasp_server_format = if let Ok(npub) = extract_npub(url) {
639 url.contains(&format!("/{npub}/{identifier}.git")) 639 url.contains(&format!("/{npub}/{identifier}.git"))
640 } else { 640 } else {
641 false 641 false
642 }; 642 };
643 if !clone_url_is_ngit_relay_format { 643 if !clone_url_is_grasp_server_format {
644 continue; 644 continue;
645 } 645 }
646 646
647 let matches_relay = relays.iter().any(|r| { 647 let matches_relay = relays.iter().any(|r| {
648 normalize_ngit_relay_url(&r.to_string()) 648 normalize_grasp_server_url(&r.to_string())
649 .is_ok_and(|r| r.eq(&formatted_as_ngit_relay_url)) 649 .is_ok_and(|r| r.eq(&formatted_as_grasp_server_url))
650 }); 650 });
651 if !matches_relay { 651 if !matches_relay {
652 continue; 652 continue;
653 } 653 }
654 654
655 let matches_blossoms = blossoms.iter().any(|r| { 655 let matches_blossoms = blossoms.iter().any(|r| {
656 normalize_ngit_relay_url(r.as_str()).is_ok_and(|r| r.eq(&formatted_as_ngit_relay_url)) 656 normalize_grasp_server_url(r.as_str())
657 .is_ok_and(|r| r.eq(&formatted_as_grasp_server_url))
657 }); 658 });
658 if !matches_blossoms { 659 if !matches_blossoms {
659 continue; 660 continue;
660 } 661 }
661 662
662 existing_ngit_relays.push(formatted_as_ngit_relay_url); 663 existing_grasp_servers.push(formatted_as_grasp_server_url);
663 } 664 }
664 existing_ngit_relays 665 existing_grasp_servers
665} 666}
666 667
667pub fn normalize_ngit_relay_url(url: &str) -> Result<String> { 668pub fn normalize_grasp_server_url(url: &str) -> Result<String> {
668 // Parse the URL and handle errors 669 // Parse the URL and handle errors
669 let mut parsed = Url::parse(url) 670 let mut parsed = Url::parse(url)
670 .or_else(|_| Url::parse(&format!("https://{url}"))) 671 .or_else(|_| Url::parse(&format!("https://{url}")))
@@ -716,10 +717,10 @@ pub fn extract_npub(s: &str) -> Result<&str> {
716 } 717 }
717} 718}
718 719
719pub fn is_ngit_relay(url: &str, ngit_relays: &[String]) -> bool { 720pub fn is_grasp_server(url: &str, grasp_servers: &[String]) -> bool {
720 if !ngit_relays.is_empty() { 721 if !grasp_servers.is_empty() {
721 if let Ok(n) = normalize_ngit_relay_url(url) { 722 if let Ok(n) = normalize_grasp_server_url(url) {
722 return ngit_relays.contains(&n); 723 return grasp_servers.contains(&n);
723 } 724 }
724 } 725 }
725 false 726 false
@@ -1005,7 +1006,7 @@ mod tests {
1005 } 1006 }
1006 1007
1007 #[test] 1008 #[test]
1008 fn normalize_ngit_relay_url_all_checks() -> Result<()> { 1009 fn normalize_grasp_server_url_all_checks() -> Result<()> {
1009 let test_cases = vec![ 1010 let test_cases = vec![
1010 ("https://sub.domain.org", "sub.domain.org"), 1011 ("https://sub.domain.org", "sub.domain.org"),
1011 ("wss://sub.domain.org", "sub.domain.org"), 1012 ("wss://sub.domain.org", "sub.domain.org"),
@@ -1035,7 +1036,7 @@ mod tests {
1035 ]; 1036 ];
1036 1037
1037 for (input, expected) in test_cases { 1038 for (input, expected) in test_cases {
1038 let normalized = normalize_ngit_relay_url(input)?; 1039 let normalized = normalize_grasp_server_url(input)?;
1039 assert_eq!(normalized, expected); 1040 assert_eq!(normalized, expected);
1040 } 1041 }
1041 Ok(()) 1042 Ok(())