upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-08-07 08:46:45 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-08-07 17:25:55 +0100
commitb27cee69f89a08cc8e97de705212440239e6049b (patch)
tree335c704bc9efc6ca15a1dc43894f2c13630a62e9 /src
parentafaa472196059bbfbd41a39b23d8ffb4c28d0805 (diff)
refactor: abstract `is_grasp_server_clone_url`
so we can use it elsehwere
Diffstat (limited to 'src')
-rw-r--r--src/lib/repo_ref.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index 5e857e9..b2bd381 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -326,12 +326,7 @@ impl RepoRef {
326 326
327 // returns false if already present so didn't need adding 327 // returns false if already present so didn't need adding
328 pub fn add_grasp_server(&mut self, clone_url: &str) -> Result<bool> { 328 pub fn add_grasp_server(&mut self, clone_url: &str) -> Result<bool> {
329 if !clone_url.starts_with("http") { 329 if !is_grasp_server_clone_url(clone_url) {
330 bail!("invalid grasp server clone url");
331 }
332 extract_npub(clone_url)
333 .context("invalid grasp server clone url. does not contain valid npub")?;
334 if !(clone_url.ends_with(".git") || clone_url.ends_with(".git/")) {
335 bail!("invalid grasp server clone url. does not end with .git"); 330 bail!("invalid grasp server clone url. does not end with .git");
336 } 331 }
337 332
@@ -739,7 +734,6 @@ pub fn extract_npub(s: &str) -> Result<&str> {
739 } 734 }
740} 735}
741 736
742// this should be called is_grasp_server_in_list
743pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool { 737pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool {
744 if !grasp_servers.is_empty() { 738 if !grasp_servers.is_empty() {
745 if let Ok(url) = normalize_grasp_server_url(url) { 739 if let Ok(url) = normalize_grasp_server_url(url) {
@@ -758,6 +752,12 @@ pub fn is_grasp_server_in_list(url: &str, grasp_servers: &[String]) -> bool {
758 } 752 }
759} 753}
760 754
755pub fn is_grasp_server_clone_url(url: &str) -> bool {
756 extract_npub(url).is_ok()
757 && (url.ends_with(".git") || url.ends_with(".git/"))
758 && url.starts_with("http")
759}
760
761pub fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> { 761pub fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> {
762 let grasp_server_url = normalize_grasp_server_url(url)?; 762 let grasp_server_url = normalize_grasp_server_url(url)?;
763 if grasp_server_url.contains("http://") { 763 if grasp_server_url.contains("http://") {