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:
Diffstat (limited to 'src')
-rw-r--r--src/bin/git_remote_nostr/main.rs8
-rw-r--r--src/bin/ngit/sub_commands/init.rs3
-rw-r--r--src/bin/ngit/sub_commands/list.rs6
-rw-r--r--src/bin/ngit/sub_commands/login.rs11
-rw-r--r--src/bin/ngit/sub_commands/send.rs7
-rw-r--r--src/lib/client.rs42
6 files changed, 65 insertions, 12 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index daa924f..29731e2 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -14,7 +14,11 @@ use std::{
14use anyhow::{Context, Result, bail}; 14use anyhow::{Context, Result, bail};
15use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache}; 15use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache};
16use git::{RepoActions, nostr_url::NostrUrlDecoded}; 16use git::{RepoActions, nostr_url::NostrUrlDecoded};
17use ngit::{client, git, login::existing::load_existing_login}; 17use ngit::{
18 client::{self, Params},
19 git,
20 login::existing::load_existing_login,
21};
18use nostr::nips::nip19::Nip19Coordinate; 22use nostr::nips::nip19::Nip19Coordinate;
19use utils::read_line; 23use utils::read_line;
20 24
@@ -33,7 +37,7 @@ async fn main() -> Result<()> {
33 37
34 let git_repo_path = git_repo.get_path()?; 38 let git_repo_path = git_repo.get_path()?;
35 39
36 let mut client = Client::default(); 40 let mut client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo)));
37 41
38 if let Ok((signer, _, _)) = load_existing_login( 42 if let Ok((signer, _, _)) = load_existing_login(
39 &Some(&git_repo), 43 &Some(&git_repo),
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 3c58a52..ee5f1ab 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -4,6 +4,7 @@ use anyhow::{Context, Result};
4use console::{Style, Term}; 4use console::{Style, Term};
5use ngit::{ 5use ngit::{
6 cli_interactor::PromptConfirmParms, 6 cli_interactor::PromptConfirmParms,
7 client::Params,
7 git::nostr_url::{NostrUrlDecoded, save_nip05_to_git_config_cache}, 8 git::nostr_url::{NostrUrlDecoded, save_nip05_to_git_config_cache},
8}; 9};
9use nostr::{ 10use nostr::{
@@ -68,7 +69,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
68 // TODO: check for empty repo 69 // TODO: check for empty repo
69 // TODO: check for existing maintaiers file 70 // TODO: check for existing maintaiers file
70 71
71 let mut client = Client::default(); 72 let mut client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo)));
72 73
73 let repo_coordinate = (try_and_get_repo_coordinates_when_remote_unknown(&git_repo).await).ok(); 74 let repo_coordinate = (try_and_get_repo_coordinates_when_remote_unknown(&git_repo).await).ok();
74 75
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs
index e8d2e97..2c91e66 100644
--- a/src/bin/ngit/sub_commands/list.rs
+++ b/src/bin/ngit/sub_commands/list.rs
@@ -2,7 +2,9 @@ use std::{io::Write, ops::Add};
2 2
3use anyhow::{Context, Result, bail}; 3use anyhow::{Context, Result, bail};
4use ngit::{ 4use ngit::{
5 client::{get_all_proposal_patch_events_from_cache, get_proposals_and_revisions_from_cache}, 5 client::{
6 Params, get_all_proposal_patch_events_from_cache, get_proposals_and_revisions_from_cache,
7 },
6 git_events::{ 8 git_events::{
7 get_commit_id_from_patch, get_most_recent_patch_with_ancestors, status_kinds, tag_value, 9 get_commit_id_from_patch, get_most_recent_patch_with_ancestors, status_kinds, tag_value,
8 }, 10 },
@@ -31,7 +33,7 @@ pub async fn launch() -> Result<()> {
31 // TODO: check for existing maintaiers file 33 // TODO: check for existing maintaiers file
32 // TODO: check for other claims 34 // TODO: check for other claims
33 35
34 let client = Client::default(); 36 let client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo)));
35 37
36 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; 38 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?;
37 39
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs
index e76a089..ed2414a 100644
--- a/src/bin/ngit/sub_commands/login.rs
+++ b/src/bin/ngit/sub_commands/login.rs
@@ -2,6 +2,7 @@ use anyhow::{Context, Result};
2use clap; 2use clap;
3use ngit::{ 3use ngit::{
4 cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, 4 cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms},
5 client::Params,
5 git::{get_git_config_item, remove_git_config_item}, 6 git::{get_git_config_item, remove_git_config_item},
6 login::{SignerInfoSource, existing::load_existing_login}, 7 login::{SignerInfoSource, existing::load_existing_login},
7}; 8};
@@ -25,15 +26,17 @@ pub struct SubCommandArgs {
25} 26}
26 27
27pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> { 28pub async fn launch(args: &Cli, command_args: &SubCommandArgs) -> Result<()> {
29 let git_repo_result = Repo::discover().context("failed to find a git repository");
30 let git_repo = { git_repo_result.ok() };
31
28 let client = if command_args.offline { 32 let client = if command_args.offline {
29 None 33 None
30 } else { 34 } else {
31 Some(Client::default()) 35 Some(Client::new(Params::with_git_config_relay_defaults(
36 &git_repo.as_ref(),
37 )))
32 }; 38 };
33 39
34 let git_repo_result = Repo::discover().context("failed to find a git repository");
35 let git_repo = { git_repo_result.ok() };
36
37 let (logged_out, log_in_locally_only) = logout(git_repo.as_ref(), command_args.local).await?; 40 let (logged_out, log_in_locally_only) = logout(git_repo.as_ref(), command_args.local).await?;
38 if logged_out || log_in_locally_only { 41 if logged_out || log_in_locally_only {
39 fresh_login_or_signup( 42 fresh_login_or_signup(
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs
index 9fc00d9..5a5acc8 100644
--- a/src/bin/ngit/sub_commands/send.rs
+++ b/src/bin/ngit/sub_commands/send.rs
@@ -2,7 +2,10 @@ use std::path::Path;
2 2
3use anyhow::{Context, Result, bail}; 3use anyhow::{Context, Result, bail};
4use console::Style; 4use console::Style;
5use ngit::{client::send_events, git_events::generate_cover_letter_and_patch_events}; 5use ngit::{
6 client::{Params, send_events},
7 git_events::generate_cover_letter_and_patch_events,
8};
6use nostr::{ 9use nostr::{
7 ToBech32, 10 ToBech32,
8 nips::{nip10::Marker, nip19::Nip19Event}, 11 nips::{nip10::Marker, nip19::Nip19Event},
@@ -52,7 +55,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re
52 .get_main_or_master_branch() 55 .get_main_or_master_branch()
53 .context("the default branches (main or master) do not exist")?; 56 .context("the default branches (main or master) do not exist")?;
54 57
55 let mut client = Client::default(); 58 let mut client = Client::new(Params::with_git_config_relay_defaults(&Some(&git_repo)));
56 59
57 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?; 60 let repo_coordinates = get_repo_coordinates_when_remote_unknown(&git_repo, &client).await?;
58 61
diff --git a/src/lib/client.rs b/src/lib/client.rs
index 6c6d81e..7cd3c46 100644
--- a/src/lib/client.rs
+++ b/src/lib/client.rs
@@ -44,7 +44,7 @@ use nostr_sdk::{
44 44
45use crate::{ 45use crate::{
46 get_dirs, 46 get_dirs,
47 git::{Repo, RepoActions}, 47 git::{Repo, RepoActions, get_git_config_item},
48 git_events::{ 48 git_events::{
49 event_is_cover_letter, event_is_patch_set_root, event_is_revision_root, status_kinds, 49 event_is_cover_letter, event_is_patch_set_root, event_is_revision_root, status_kinds,
50 }, 50 },
@@ -659,6 +659,46 @@ impl Default for Params {
659 } 659 }
660 } 660 }
661} 661}
662impl Params {
663 pub fn with_git_config_relay_defaults(git_repo: &Option<&Repo>) -> Self {
664 let mut params = Params::default();
665 if std::env::var("NGITTEST").is_err() {
666 // ignore git config settings under test
667 if let Ok(Some(relay_defaults)) =
668 get_git_config_item(git_repo, "nostr.relay-default-set")
669 {
670 let new_default_relays: Vec<String> = relay_defaults
671 .split(';')
672 .filter_map(|url| RelayUrl::parse(url).ok()) // Attempt to parse and filter out errors
673 .map(|relay_url| relay_url.to_string()) // Convert RelayUrl back to String
674 .collect();
675 // elsewhere it is assumed this isn't empty
676 if !new_default_relays.is_empty() {
677 params.fallback_relays = new_default_relays;
678 }
679 }
680 if let Ok(Some(relay_blasters)) =
681 get_git_config_item(git_repo, "nostr.relay-blaster-set")
682 {
683 params.blaster_relays = relay_blasters
684 .split(';')
685 .filter_map(|url| RelayUrl::parse(url).ok()) // Attempt to parse and filter out errors
686 .map(|relay_url| relay_url.to_string()) // Convert RelayUrl back to String
687 .collect();
688 }
689 if let Ok(Some(relay_signer)) =
690 get_git_config_item(git_repo, "nostr.relay-signer-fallback-set")
691 {
692 params.fallback_signer_relays = relay_signer
693 .split(';')
694 .filter_map(|url| RelayUrl::parse(url).ok()) // Attempt to parse and filter out errors
695 .map(|relay_url| relay_url.to_string()) // Convert RelayUrl back to String
696 .collect();
697 }
698 }
699 params
700 }
701}
662 702
663fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> { 703fn get_dedup_events(relay_results: Vec<Result<Vec<nostr::Event>>>) -> Vec<Event> {
664 let mut dedup_events: Vec<Event> = vec![]; 704 let mut dedup_events: Vec<Event> = vec![];