upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-05-23 10:01:29 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-05-23 10:01:29 +0100
commit686604665395385600ef8f1b5238a775249552a1 (patch)
tree56a4c7a956e14dfbcdd4a518096968abc69583a6 /src/bin/git_remote_nostr
parentcc9a3a1d8526373625246504f72f338fd89c8d8b (diff)
feat: only try http(s) for ngit-relays
otherwise it tries all the protocols and reprots on each
Diffstat (limited to 'src/bin/git_remote_nostr')
-rw-r--r--src/bin/git_remote_nostr/fetch.rs7
-rw-r--r--src/bin/git_remote_nostr/list.rs21
-rw-r--r--src/bin/git_remote_nostr/push.rs9
-rw-r--r--src/bin/git_remote_nostr/utils.rs18
4 files changed, 44 insertions, 11 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index 34a02fc..adc68b3 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -18,7 +18,7 @@ use ngit::{
18 }, 18 },
19 git_events::tag_value, 19 git_events::tag_value,
20 login::get_curent_user, 20 login::get_curent_user,
21 repo_ref::RepoRef, 21 repo_ref::{RepoRef, is_ngit_relay},
22}; 22};
23use nostr::nips::nip19; 23use nostr::nips::nip19;
24use nostr_sdk::{Event, ToBech32}; 24use nostr_sdk::{Event, ToBech32};
@@ -54,6 +54,7 @@ pub async fn run_fetch(
54 git_server_url, 54 git_server_url,
55 &repo_ref.to_nostr_git_url(&None), 55 &repo_ref.to_nostr_git_url(&None),
56 &term, 56 &term,
57 is_ngit_relay(git_server_url, &repo_ref.ngit_relays()),
57 ) { 58 ) {
58 errors.push(error); 59 errors.push(error);
59 } else { 60 } else {
@@ -163,6 +164,7 @@ pub fn fetch_from_git_server(
163 git_server_url: &str, 164 git_server_url: &str,
164 decoded_nostr_url: &NostrUrlDecoded, 165 decoded_nostr_url: &NostrUrlDecoded,
165 term: &console::Term, 166 term: &console::Term,
167 is_ngit_relay: bool,
166) -> Result<()> { 168) -> Result<()> {
167 let already_have_oids = oids 169 let already_have_oids = oids
168 .iter() 170 .iter()
@@ -173,7 +175,8 @@ pub fn fetch_from_git_server(
173 175
174 let server_url = git_server_url.parse::<CloneUrl>()?; 176 let server_url = git_server_url.parse::<CloneUrl>()?;
175 177
176 let protocols_to_attempt = get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url); 178 let protocols_to_attempt =
179 get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay);
177 180
178 let mut failed_protocols = vec![]; 181 let mut failed_protocols = vec![];
179 let mut success = false; 182 let mut success = false;
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs
index 2d233ae..bf16f89 100644
--- a/src/bin/git_remote_nostr/list.rs
+++ b/src/bin/git_remote_nostr/list.rs
@@ -13,7 +13,7 @@ use ngit::{
13 }, 13 },
14 git_events::event_to_cover_letter, 14 git_events::event_to_cover_letter,
15 login::get_curent_user, 15 login::get_curent_user,
16 repo_ref, 16 repo_ref::{self, is_ngit_relay},
17}; 17};
18use nostr_sdk::hashes::sha1::Hash as Sha1Hash; 18use nostr_sdk::hashes::sha1::Hash as Sha1Hash;
19use repo_ref::RepoRef; 19use repo_ref::RepoRef;
@@ -41,6 +41,7 @@ pub async fn run_list(
41 git_repo, 41 git_repo,
42 &repo_ref.git_server, 42 &repo_ref.git_server,
43 &repo_ref.to_nostr_git_url(&None), 43 &repo_ref.to_nostr_git_url(&None),
44 &repo_ref.ngit_relays(),
44 ); 45 );
45 46
46 let mut state = if let Some(nostr_state) = nostr_state { 47 let mut state = if let Some(nostr_state) = nostr_state {
@@ -131,6 +132,7 @@ async fn get_open_and_draft_proposals_state(
131 git_server_url, 132 git_server_url,
132 &repo_ref.to_nostr_git_url(&None), 133 &repo_ref.to_nostr_git_url(&None),
133 term, 134 term,
135 is_ngit_relay(git_server_url, &repo_ref.ngit_relays()),
134 ) 136 )
135 .is_ok() 137 .is_ok()
136 { 138 {
@@ -174,12 +176,19 @@ pub fn list_from_remotes(
174 term: &console::Term, 176 term: &console::Term,
175 git_repo: &Repo, 177 git_repo: &Repo,
176 git_servers: &Vec<String>, 178 git_servers: &Vec<String>,
177 decoded_nostr_url: &NostrUrlDecoded, // Add this parameter 179 decoded_nostr_url: &NostrUrlDecoded,
180 ngit_relays: &[String],
178) -> HashMap<String, HashMap<String, String>> { 181) -> HashMap<String, HashMap<String, String>> {
179 let mut remote_states = HashMap::new(); 182 let mut remote_states = HashMap::new();
180 let mut errors = HashMap::new(); 183 let mut errors = HashMap::new();
181 for url in git_servers { 184 for url in git_servers {
182 match list_from_remote(term, git_repo, url, decoded_nostr_url) { 185 match list_from_remote(
186 term,
187 git_repo,
188 url,
189 decoded_nostr_url,
190 is_ngit_relay(url, ngit_relays),
191 ) {
183 Err(error) => { 192 Err(error) => {
184 errors.insert(url, error); 193 errors.insert(url, error);
185 } 194 }
@@ -195,10 +204,12 @@ pub fn list_from_remote(
195 term: &console::Term, 204 term: &console::Term,
196 git_repo: &Repo, 205 git_repo: &Repo,
197 git_server_url: &str, 206 git_server_url: &str,
198 decoded_nostr_url: &NostrUrlDecoded, // Add this parameter 207 decoded_nostr_url: &NostrUrlDecoded,
208 is_ngit_relay: bool,
199) -> Result<HashMap<String, String>> { 209) -> Result<HashMap<String, String>> {
200 let server_url = git_server_url.parse::<CloneUrl>()?; 210 let server_url = git_server_url.parse::<CloneUrl>()?;
201 let protocols_to_attempt = get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url); 211 let protocols_to_attempt =
212 get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay);
202 213
203 let mut failed_protocols = vec![]; 214 let mut failed_protocols = vec![];
204 let mut remote_state: Option<HashMap<String, String>> = None; 215 let mut remote_state: Option<HashMap<String, String>> = None;
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index 4eae92f..a34d729 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -27,7 +27,7 @@ use ngit::{
27 }, 27 },
28 git_events::{self, event_to_cover_letter, get_event_root}, 28 git_events::{self, event_to_cover_letter, get_event_root},
29 login::{self, user::UserRef}, 29 login::{self, user::UserRef},
30 repo_ref::{self, get_repo_config_from_yaml}, 30 repo_ref::{self, get_repo_config_from_yaml, is_ngit_relay},
31 repo_state, 31 repo_state,
32}; 32};
33use nostr::nips::nip10::Marker; 33use nostr::nips::nip10::Marker;
@@ -49,6 +49,7 @@ use crate::{
49 }, 49 },
50}; 50};
51 51
52#[allow(clippy::too_many_lines)]
52pub async fn run_push( 53pub async fn run_push(
53 git_repo: &Repo, 54 git_repo: &Repo,
54 repo_ref: &RepoRef, 55 repo_ref: &RepoRef,
@@ -79,6 +80,7 @@ pub async fn run_push(
79 git_repo, 80 git_repo,
80 &repo_ref.git_server, 81 &repo_ref.git_server,
81 &repo_ref.to_nostr_git_url(&None), 82 &repo_ref.to_nostr_git_url(&None),
83 &repo_ref.ngit_relays(),
82 ) 84 )
83 }); 85 });
84 86
@@ -161,6 +163,7 @@ pub async fn run_push(
161 &repo_ref.to_nostr_git_url(&None), 163 &repo_ref.to_nostr_git_url(&None),
162 &remote_refspecs, 164 &remote_refspecs,
163 &term, 165 &term,
166 is_ngit_relay(&git_server_url, &repo_ref.ngit_relays()),
164 ); 167 );
165 } 168 }
166 } 169 }
@@ -412,9 +415,11 @@ fn push_to_remote(
412 decoded_nostr_url: &NostrUrlDecoded, 415 decoded_nostr_url: &NostrUrlDecoded,
413 remote_refspecs: &[String], 416 remote_refspecs: &[String],
414 term: &Term, 417 term: &Term,
418 is_ngit_relay: bool,
415) -> Result<()> { 419) -> Result<()> {
416 let server_url = git_server_url.parse::<CloneUrl>()?; 420 let server_url = git_server_url.parse::<CloneUrl>()?;
417 let protocols_to_attempt = get_write_protocols_to_try(git_repo, &server_url, decoded_nostr_url); 421 let protocols_to_attempt =
422 get_write_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay);
418 423
419 let mut failed_protocols = vec![]; 424 let mut failed_protocols = vec![];
420 let mut success = false; 425 let mut success = false;
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index 3a9f07d..2c77baa 100644
--- a/src/bin/git_remote_nostr/utils.rs
+++ b/src/bin/git_remote_nostr/utils.rs
@@ -216,8 +216,15 @@ pub fn get_read_protocols_to_try(
216 git_repo: &Repo, 216 git_repo: &Repo,
217 server_url: &CloneUrl, 217 server_url: &CloneUrl,
218 decoded_nostr_url: &NostrUrlDecoded, 218 decoded_nostr_url: &NostrUrlDecoded,
219 is_ngit_relay: bool,
219) -> Vec<ServerProtocol> { 220) -> Vec<ServerProtocol> {
220 if server_url.protocol() == ServerProtocol::Filesystem { 221 if is_ngit_relay {
222 if server_url.protocol() == ServerProtocol::Http {
223 vec![(ServerProtocol::UnauthHttp)]
224 } else {
225 vec![(ServerProtocol::UnauthHttps)]
226 }
227 } else if server_url.protocol() == ServerProtocol::Filesystem {
221 vec![(ServerProtocol::Filesystem)] 228 vec![(ServerProtocol::Filesystem)]
222 } else if let Some(protocol) = &decoded_nostr_url.protocol { 229 } else if let Some(protocol) = &decoded_nostr_url.protocol {
223 vec![protocol.clone()] 230 vec![protocol.clone()]
@@ -254,8 +261,15 @@ pub fn get_write_protocols_to_try(
254 git_repo: &Repo, 261 git_repo: &Repo,
255 server_url: &CloneUrl, 262 server_url: &CloneUrl,
256 decoded_nostr_url: &NostrUrlDecoded, 263 decoded_nostr_url: &NostrUrlDecoded,
264 is_ngit_relay: bool,
257) -> Vec<ServerProtocol> { 265) -> Vec<ServerProtocol> {
258 if server_url.protocol() == ServerProtocol::Filesystem { 266 if is_ngit_relay {
267 if server_url.protocol() == ServerProtocol::Http {
268 vec![(ServerProtocol::UnauthHttp)]
269 } else {
270 vec![(ServerProtocol::UnauthHttps)]
271 }
272 } else if server_url.protocol() == ServerProtocol::Filesystem {
259 vec![(ServerProtocol::Filesystem)] 273 vec![(ServerProtocol::Filesystem)]
260 } else if let Some(protocol) = &decoded_nostr_url.protocol { 274 } else if let Some(protocol) = &decoded_nostr_url.protocol {
261 vec![protocol.clone()] 275 vec![protocol.clone()]