From 4ee83e2fe5335a8afd78439c35f029c4a472e797 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 16 Dec 2024 09:00:46 +0000 Subject: chore: bump nix flake rust nightly `fmt` overlay update the rust nightly `fmt` overlay which needs to be pinned to a specific version (this case by date) update formatting in main files via `cargo fmt` --- src/bin/git_remote_nostr/fetch.rs | 10 +-- src/bin/git_remote_nostr/list.rs | 6 +- src/bin/git_remote_nostr/main.rs | 6 +- src/bin/git_remote_nostr/push.rs | 62 ++++++-------- src/bin/git_remote_nostr/utils.rs | 17 ++-- src/bin/ngit/cli.rs | 2 +- src/bin/ngit/sub_commands/export_keys.rs | 2 +- src/bin/ngit/sub_commands/init.rs | 12 +-- src/bin/ngit/sub_commands/list.rs | 19 ++--- src/bin/ngit/sub_commands/login.rs | 4 +- src/bin/ngit/sub_commands/logout.rs | 2 +- src/bin/ngit/sub_commands/send.rs | 17 ++-- src/lib/cli_interactor.rs | 2 +- src/lib/client.rs | 140 ++++++++++++++----------------- src/lib/git/identify_ahead_behind.rs | 8 +- src/lib/git/mod.rs | 87 +++++++++---------- src/lib/git/nostr_url.rs | 136 ++++++++++++++---------------- src/lib/git_events.rs | 22 +++-- src/lib/login/existing.rs | 8 +- src/lib/login/fresh.rs | 10 +-- src/lib/login/mod.rs | 14 ++-- src/lib/login/user.rs | 4 +- src/lib/mod.rs | 2 +- src/lib/repo_ref.rs | 46 +++++----- 24 files changed, 284 insertions(+), 354 deletions(-) (limited to 'src') diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 458c6d8..7012955 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs @@ -6,15 +6,15 @@ use std::{ time::Instant, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use auth_git2::GitAuthenticator; use git2::{Progress, Repository}; use ngit::{ cli_interactor::count_lines_per_msg_vec, git::{ + Repo, RepoActions, nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, utils::check_ssh_keys, - Repo, RepoActions, }, git_events::tag_value, login::get_curent_user, @@ -24,9 +24,9 @@ use nostr::nips::nip19; use nostr_sdk::{Event, ToBech32}; use crate::utils::{ - fetch_or_list_error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name, - get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and, - set_protocol_preference, Direction, + Direction, fetch_or_list_error_is_not_authentication_failure, + find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, + get_read_protocols_to_try, join_with_and, set_protocol_preference, }; pub async fn run_fetch( diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 9171544..bba15aa 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs @@ -1,7 +1,7 @@ use core::str; use std::collections::HashMap; -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use auth_git2::GitAuthenticator; use client::get_state_from_cache; use git::RepoActions; @@ -22,9 +22,9 @@ use crate::{ fetch::{fetch_from_git_server, make_commits_for_proposal}, git::Repo, utils::{ - fetch_or_list_error_is_not_authentication_failure, get_open_proposals, + Direction, fetch_or_list_error_is_not_authentication_failure, get_open_proposals, get_read_protocols_to_try, get_short_git_server_name, join_with_and, - set_protocol_preference, Direction, + set_protocol_preference, }, }; diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs index 1a21341..e6f7af3 100644 --- a/src/bin/git_remote_nostr/main.rs +++ b/src/bin/git_remote_nostr/main.rs @@ -11,9 +11,9 @@ use std::{ path::{Path, PathBuf}, }; -use anyhow::{bail, Context, Result}; -use client::{consolidate_fetch_reports, get_repo_ref_from_cache, Connect}; -use git::{nostr_url::NostrUrlDecoded, RepoActions}; +use anyhow::{Context, Result, bail}; +use client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache}; +use git::{RepoActions, nostr_url::NostrUrlDecoded}; use ngit::{client, git, login::existing::load_existing_login}; use nostr::nips::nip01::Coordinate; use utils::read_line; diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index f2ac169..e8e1587 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -6,17 +6,17 @@ use std::{ time::Instant, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{Context, Result, anyhow, bail}; use auth_git2::GitAuthenticator; use client::{ - get_events_from_local_cache, get_state_from_cache, send_events, sign_event, STATE_KIND, + STATE_KIND, get_events_from_local_cache, get_state_from_cache, send_events, sign_event, }; use console::Term; -use git::{sha1_to_oid, RepoActions}; -use git2::{Oid, Repository}; +use git::{RepoActions, sha1_to_oid}; use git_events::{ generate_cover_letter_and_patch_events, generate_patch_event, get_commit_id_from_patch, }; +use git2::{Oid, Repository}; use ngit::{ cli_interactor::count_lines_per_msg_vec, client::{self, get_event_from_cache_by_id}, @@ -32,8 +32,8 @@ use ngit::{ }; use nostr::nips::nip10::Marker; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, - RelayUrl, Tag, + Event, EventBuilder, EventId, Kind, NostrSigner, PublicKey, RelayUrl, Tag, + hashes::sha1::Hash as Sha1Hash, }; use repo_ref::RepoRef; use repo_state::RepoState; @@ -43,9 +43,10 @@ use crate::{ git::Repo, list::list_from_remotes, utils::{ - find_proposal_and_patches_by_branch_name, get_all_proposals, get_remote_name_by_url, - get_short_git_server_name, get_write_protocols_to_try, join_with_and, - push_error_is_not_authentication_failure, read_line, set_protocol_preference, Direction, + Direction, find_proposal_and_patches_by_branch_name, get_all_proposals, + get_remote_name_by_url, get_short_git_server_name, get_write_protocols_to_try, + join_with_and, push_error_is_not_authentication_failure, read_line, + set_protocol_preference, }, }; @@ -1023,13 +1024,10 @@ async fn get_merged_status_events( let (ahead, _) = git_repo.get_commits_ahead_behind(&tip_of_remote_branch, &tip_of_pushed_branch)?; - let commit_events = get_events_from_local_cache( - git_repo.get_path()?, - vec![ - nostr::Filter::default().kind(nostr::Kind::GitPatch), - // TODO: limit by repo_ref - ], - ) + let commit_events = get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().kind(nostr::Kind::GitPatch), + // TODO: limit by repo_ref + ]) .await?; let merged_proposals_info = @@ -1106,12 +1104,9 @@ async fn get_merged_proposals_info( proposals.entry(proposal_id).or_default(); // ignore revisions without all the merged commits if entry_revision_id == &revision_id { - merged_patches.insert( - *commit_hash, - MergedPRCommitType::PatchCommit { - event_id: patch_event.id, - }, - ); + merged_patches.insert(*commit_hash, MergedPRCommitType::PatchCommit { + event_id: patch_event.id, + }); } } } @@ -1136,12 +1131,9 @@ async fn get_merged_proposals_info( proposals.entry(proposal_id).or_default(); // ignore revisions without all the applied commits if entry_revision_id == &revision_id { - merged_patches.insert( - *commit_hash, - MergedPRCommitType::PatchApplied { - event_id: patch_event.id, - }, - ); + merged_patches.insert(*commit_hash, MergedPRCommitType::PatchApplied { + event_id: patch_event.id, + }); } } } @@ -1379,10 +1371,9 @@ async fn get_proposal_and_revision_root_from_patch( .clone(), )?; - get_events_from_local_cache( - git_repo.get_path()?, - vec![nostr::Filter::default().id(proposal_or_revision_id)], - ) + get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().id(proposal_or_revision_id), + ]) .await? .first() .unwrap() @@ -1538,10 +1529,9 @@ impl BuildRepoState for RepoState { ) -> Result { let mut tags = vec![Tag::identifier(identifier.clone())]; for (name, value) in &state { - tags.push(Tag::custom( - nostr_sdk::TagKind::Custom(name.into()), - vec![value.clone()], - )); + tags.push(Tag::custom(nostr_sdk::TagKind::Custom(name.into()), vec![ + value.clone(), + ])); } let event = sign_event(EventBuilder::new(STATE_KIND, "").tags(tags), signer).await?; Ok(RepoState { diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 8e89652..15ebb10 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs @@ -6,7 +6,7 @@ use std::{ str::FromStr, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use git2::Repository; use ngit::{ client::{ @@ -14,8 +14,8 @@ use ngit::{ get_proposals_and_revisions_from_cache, }, git::{ - nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, Repo, RepoActions, + nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, }, git_events::{ event_is_revision_root, get_most_recent_patch_with_ancestors, @@ -108,14 +108,11 @@ pub async fn get_open_proposals( .collect(); let statuses: Vec = { - let mut statuses = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(status_kinds().clone()) - .events(proposals.iter().map(|e| e.id)), - ], - ) + let mut statuses = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(status_kinds().clone()) + .events(proposals.iter().map(|e| e.id)), + ]) .await?; statuses.sort_by_key(|e| e.created_at); statuses.reverse(); diff --git a/src/bin/ngit/cli.rs b/src/bin/ngit/cli.rs index 1737a9f..60bc5d2 100644 --- a/src/bin/ngit/cli.rs +++ b/src/bin/ngit/cli.rs @@ -1,4 +1,4 @@ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::{Parser, Subcommand}; use ngit::login::SignerInfo; diff --git a/src/bin/ngit/sub_commands/export_keys.rs b/src/bin/ngit/sub_commands/export_keys.rs index 54a716f..45b1b89 100644 --- a/src/bin/ngit/sub_commands/export_keys.rs +++ b/src/bin/ngit/sub_commands/export_keys.rs @@ -2,9 +2,9 @@ use anyhow::{Context, Result}; use ngit::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, login::{ + SignerInfo, SignerInfoSource, existing::{get_signer_info, load_existing_login}, fresh::generate_qr, - SignerInfo, SignerInfoSource, }, }; diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 0894f41..80e182b 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs @@ -3,18 +3,18 @@ use std::collections::HashMap; use anyhow::{Context, Result}; use console::Style; use ngit::{cli_interactor::PromptConfirmParms, git::nostr_url::NostrUrlDecoded}; -use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, ToBech32}; +use nostr::{FromBech32, PublicKey, ToBech32, nips::nip01::Coordinate}; use nostr_sdk::{Kind, RelayUrl}; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, cli_interactor::{Interactor, InteractorPrompt, PromptInputParms}, - client::{fetching_with_report, get_repo_ref_from_cache, send_events, Client, Connect}, - git::{nostr_url::convert_clone_url_to_https, Repo, RepoActions}, + client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache, send_events}, + git::{Repo, RepoActions, nostr_url::convert_clone_url_to_https}, login, repo_ref::{ - extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, - try_and_get_repo_coordinates_when_remote_unknown, RepoRef, + RepoRef, extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, + try_and_get_repo_coordinates_when_remote_unknown, }, }; diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index ee015ef..9b84c1b 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs @@ -1,6 +1,6 @@ use std::{io::Write, ops::Add}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use ngit::{ client::{get_all_proposal_patch_events_from_cache, get_proposals_and_revisions_from_cache}, git_events::{ @@ -12,9 +12,9 @@ use nostr_sdk::Kind; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms}, client::{ - fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, Client, Connect, + Client, Connect, fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, }, - git::{str_to_sha1, Repo, RepoActions}, + git::{Repo, RepoActions, str_to_sha1}, git_events::{ commit_msg_from_patch_oneliner, event_is_revision_root, event_to_cover_letter, patch_supports_commit_ids, @@ -47,14 +47,11 @@ pub async fn launch() -> Result<()> { } let statuses: Vec = { - let mut statuses = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(status_kinds().clone()) - .events(proposals_and_revisions.iter().map(|e| e.id)), - ], - ) + let mut statuses = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(status_kinds().clone()) + .events(proposals_and_revisions.iter().map(|e| e.id)), + ]) .await?; statuses.sort_by_key(|e| e.created_at); statuses.reverse(); diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs index ccbdf01..06236ec 100644 --- a/src/bin/ngit/sub_commands/login.rs +++ b/src/bin/ngit/sub_commands/login.rs @@ -3,11 +3,11 @@ use clap; use ngit::{ cli_interactor::{Interactor, InteractorPrompt, PromptChoiceParms}, git::{get_git_config_item, remove_git_config_item}, - login::{existing::load_existing_login, SignerInfoSource}, + login::{SignerInfoSource, existing::load_existing_login}, }; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, client::{Client, Connect}, git::Repo, login::fresh::fresh_login_or_signup, diff --git a/src/bin/ngit/sub_commands/logout.rs b/src/bin/ngit/sub_commands/logout.rs index f3f9620..2df96c8 100644 --- a/src/bin/ngit/sub_commands/logout.rs +++ b/src/bin/ngit/sub_commands/logout.rs @@ -1,7 +1,7 @@ use anyhow::{Context, Result}; use ngit::{ git::remove_git_config_item, - login::{existing::load_existing_login, SignerInfoSource}, + login::{SignerInfoSource, existing::load_existing_login}, }; use crate::{ diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs index c6c75c9..7c898bc 100644 --- a/src/bin/ngit/sub_commands/send.rs +++ b/src/bin/ngit/sub_commands/send.rs @@ -1,23 +1,23 @@ use std::path::Path; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; use ngit::{client::send_events, git_events::generate_cover_letter_and_patch_events}; use nostr::{ - nips::{nip10::Marker, nip19::Nip19Event}, ToBech32, + nips::{nip10::Marker, nip19::Nip19Event}, }; use nostr_sdk::hashes::sha1::Hash as Sha1Hash; use crate::{ - cli::{extract_signer_cli_arguments, Cli}, + cli::{Cli, extract_signer_cli_arguments}, cli_interactor::{ Interactor, InteractorPrompt, PromptConfirmParms, PromptInputParms, PromptMultiChoiceParms, }, client::{ - fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, Client, Connect, + Client, Connect, fetching_with_report, get_events_from_local_cache, get_repo_ref_from_cache, }, - git::{identify_ahead_behind, Repo, RepoActions}, + git::{Repo, RepoActions, identify_ahead_behind}, git_events::{event_is_patch_set_root, event_tag_from_nip19_or_hex}, login, repo_ref::get_repo_coordinates_when_remote_unknown, @@ -369,10 +369,9 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( public_key: _, uppercase: false, }) => { - let events = get_events_from_local_cache( - git_repo_path, - vec![nostr::Filter::new().id(*event_id)], - ) + let events = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::new().id(*event_id), + ]) .await?; if let Some(first) = events.iter().find(|e| e.id.eq(event_id)) { diff --git a/src/lib/cli_interactor.rs b/src/lib/cli_interactor.rs index 50a0f0c..1b74101 100644 --- a/src/lib/cli_interactor.rs +++ b/src/lib/cli_interactor.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password}; +use dialoguer::{Confirm, Input, Password, theme::ColorfulTheme}; use indicatif::TermLike; #[cfg(test)] use mockall::*; diff --git a/src/lib/client.rs b/src/lib/client.rs index 32f5bd7..59ec583 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs @@ -19,7 +19,7 @@ use std::{ time::Duration, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use async_trait::async_trait; use console::Style; use futures::{ @@ -29,12 +29,12 @@ use futures::{ use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, ProgressStyle}; #[cfg(test)] use mockall::*; -use nostr::{nips::nip01::Coordinate, signer::SignerBackend, Event}; +use nostr::{Event, nips::nip01::Coordinate, signer::SignerBackend}; use nostr_database::NostrEventsDatabase; use nostr_lmdb::NostrLMDB; use nostr_sdk::{ - prelude::RelayLimits, EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, RelayUrl, - SingleLetterTag, Timestamp, + EventBuilder, EventId, Kind, NostrSigner, Options, PublicKey, RelayUrl, SingleLetterTag, + Timestamp, prelude::RelayLimits, }; use crate::{ @@ -894,18 +894,16 @@ pub async fn get_state_from_cache( ) -> Result { if let Some(git_repo_path) = git_repo_path { RepoState::try_from( - get_events_from_local_cache( - git_repo_path, - vec![get_filter_state_events(&repo_ref.coordinates())], - ) + get_events_from_local_cache(git_repo_path, vec![get_filter_state_events( + &repo_ref.coordinates(), + )]) .await?, ) } else { RepoState::try_from( - get_event_from_global_cache( - git_repo_path, - vec![get_filter_state_events(&repo_ref.coordinates())], - ) + get_event_from_global_cache(git_repo_path, vec![get_filter_state_events( + &repo_ref.coordinates(), + )]) .await?, ) } @@ -975,20 +973,17 @@ async fn create_relays_request( } if let Some(git_repo_path) = git_repo_path { - for event in &get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kinds(vec![Kind::GitPatch]) - .custom_tag( - SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), - repo_coordinates_without_relays - .iter() - .map(std::string::ToString::to_string) - .collect::>(), - ), - ], - ) + for event in &get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kinds(vec![Kind::GitPatch]) + .custom_tag( + SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), + repo_coordinates_without_relays + .iter() + .map(std::string::ToString::to_string) + .collect::>(), + ), + ]) .await? { if event_is_patch_set_root(event) || event_is_revision_root(event) { @@ -998,11 +993,11 @@ async fn create_relays_request( } } - let profile_events = get_event_from_global_cache( - git_repo_path, - vec![get_filter_contributor_profiles(contributors.clone())], - ) - .await?; + let profile_events = + get_event_from_global_cache(git_repo_path, vec![get_filter_contributor_profiles( + contributors.clone(), + )]) + .await?; for c in &contributors { if let Some(event) = profile_events .iter() @@ -1564,20 +1559,17 @@ pub async fn get_proposals_and_revisions_from_cache( git_repo_path: &Path, repo_coordinates: HashSet, ) -> Result> { - let mut proposals = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .custom_tag( - nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), - repo_coordinates - .iter() - .map(std::string::ToString::to_string) - .collect::>(), - ), - ], - ) + let mut proposals = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .custom_tag( + nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), + repo_coordinates + .iter() + .map(std::string::ToString::to_string) + .collect::>(), + ), + ]) .await? .iter() .filter(|e| event_is_patch_set_root(e)) @@ -1593,29 +1585,23 @@ pub async fn get_all_proposal_patch_events_from_cache( repo_ref: &RepoRef, proposal_id: &nostr::EventId, ) -> Result> { - let mut commit_events = get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .event(*proposal_id), - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .id(*proposal_id), - ], - ) + let mut commit_events = get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .event(*proposal_id), + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .id(*proposal_id), + ]) .await?; - let permissioned_users: HashSet = [ - repo_ref.maintainers.clone(), - vec![ - commit_events - .iter() - .find(|e| e.id.eq(proposal_id)) - .context("proposal not in cache")? - .pubkey, - ], - ] + let permissioned_users: HashSet = [repo_ref.maintainers.clone(), vec![ + commit_events + .iter() + .find(|e| e.id.eq(proposal_id)) + .context("proposal not in cache")? + .pubkey, + ]] .concat() .iter() .copied() @@ -1629,15 +1615,12 @@ pub async fn get_all_proposal_patch_events_from_cache( .collect(); if !revision_roots.is_empty() { - for event in get_events_from_local_cache( - git_repo_path, - vec![ - nostr::Filter::default() - .kind(nostr::Kind::GitPatch) - .events(revision_roots) - .authors(permissioned_users.clone()), - ], - ) + for event in get_events_from_local_cache(git_repo_path, vec![ + nostr::Filter::default() + .kind(nostr::Kind::GitPatch) + .events(revision_roots) + .authors(permissioned_users.clone()), + ]) .await? { commit_events.push(event); @@ -1652,10 +1635,9 @@ pub async fn get_all_proposal_patch_events_from_cache( } pub async fn get_event_from_cache_by_id(git_repo: &Repo, event_id: &EventId) -> Result { - Ok(get_events_from_local_cache( - git_repo.get_path()?, - vec![nostr::Filter::default().id(*event_id)], - ) + Ok(get_events_from_local_cache(git_repo.get_path()?, vec![ + nostr::Filter::default().id(*event_id), + ]) .await? .first() .context("failed to find event in cache")? diff --git a/src/lib/git/identify_ahead_behind.rs b/src/lib/git/identify_ahead_behind.rs index d736522..baea687 100644 --- a/src/lib/git/identify_ahead_behind.rs +++ b/src/lib/git/identify_ahead_behind.rs @@ -184,10 +184,10 @@ mod tests { identify_ahead_behind(&git_repo, &Some("feature".to_string()), &None)?; assert_eq!(from_branch, "feature"); - assert_eq!( - ahead, - vec![oid_to_sha1(&feature_oid), oid_to_sha1(&dev_oid_first)] - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&feature_oid), + oid_to_sha1(&dev_oid_first) + ]); assert_eq!(to_branch, "main"); assert_eq!(behind, vec![]); diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index 7a7ad5d..2b78f38 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs @@ -3,12 +3,12 @@ use std::{ path::{Path, PathBuf}, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use git2::{DiffOptions, Oid, Revwalk}; pub use identify_ahead_behind::identify_ahead_behind; use nostr_sdk::{ - hashes::{sha1::Hash as Sha1Hash, Hash}, Tags, + hashes::{Hash, sha1::Hash as Sha1Hash}, }; use crate::git_events::{get_commit_id_from_patch, tag_value}; @@ -1493,10 +1493,10 @@ mod tests { &oid_to_sha1(&feature_oid), )?; assert_eq!(ahead, vec![]); - assert_eq!( - behind, - vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid),], - ); + assert_eq!(behind, vec![ + oid_to_sha1(&behind_2_oid), + oid_to_sha1(&behind_1_oid), + ],); Ok(()) } @@ -1518,10 +1518,10 @@ mod tests { &oid_to_sha1(&main_oid), &oid_to_sha1(&ahead_2_oid), )?; - assert_eq!( - ahead, - vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid),], - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&ahead_2_oid), + oid_to_sha1(&ahead_1_oid), + ],); assert_eq!(behind, vec![]); Ok(()) } @@ -1550,14 +1550,14 @@ mod tests { &oid_to_sha1(&behind_2_oid), &oid_to_sha1(&ahead_2_oid), )?; - assert_eq!( - ahead, - vec![oid_to_sha1(&ahead_2_oid), oid_to_sha1(&ahead_1_oid)], - ); - assert_eq!( - behind, - vec![oid_to_sha1(&behind_2_oid), oid_to_sha1(&behind_1_oid)], - ); + assert_eq!(ahead, vec![ + oid_to_sha1(&ahead_2_oid), + oid_to_sha1(&ahead_1_oid) + ],); + assert_eq!(behind, vec![ + oid_to_sha1(&behind_2_oid), + oid_to_sha1(&behind_1_oid) + ],); Ok(()) } } @@ -2212,10 +2212,9 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~1")?, - vec![str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")? + ],); Ok(()) } @@ -2225,10 +2224,9 @@ mod tests { let git_repo = Repo::from_path(&test_repo.dir)?; test_repo.populate_with_test_branch()?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~1")?, - vec![str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~1")?, vec![ + str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")? + ],); Ok(()) } } @@ -2242,13 +2240,10 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~2")?, - vec![ - str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, - str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~2")?, vec![ + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, + str_to_sha1("af474d8d271490e5c635aad337abdc050034b16a")?, + ],); Ok(()) } } @@ -2261,14 +2256,11 @@ mod tests { let git_repo = Repo::from_path(&test_repo.dir)?; test_repo.populate_with_test_branch()?; - assert_eq!( - git_repo.parse_starting_commits("HEAD~3")?, - vec![ - str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?, - str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, - str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("HEAD~3")?, vec![ + str_to_sha1("82ff2bcc9aa94d1bd8faee723d4c8cc190d6061c")?, + str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, + str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, + ],); Ok(()) } } @@ -2282,14 +2274,11 @@ mod tests { test_repo.populate_with_test_branch()?; test_repo.checkout("main")?; - assert_eq!( - git_repo.parse_starting_commits("af474d8..a23e6b0")?, - vec![ - str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, - str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, - str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, - ], - ); + assert_eq!(git_repo.parse_starting_commits("af474d8..a23e6b0")?, vec![ + str_to_sha1("a23e6b05aaeb7d1471b4a838b51f337d5644eeb0")?, + str_to_sha1("7ab82116068982671a8111f27dc10599172334b2")?, + str_to_sha1("431b84edc0d2fa118d63faa3c2db9c73d630a5ae")?, + ],); Ok(()) } } diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 4fbc786..6b38a93 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -1,11 +1,11 @@ use core::fmt; use std::{collections::HashMap, str::FromStr}; -use anyhow::{anyhow, bail, Context, Error, Result}; +use anyhow::{Context, Error, Result, anyhow, bail}; use nostr::nips::{nip01::Coordinate, nip05}; use nostr_sdk::{PublicKey, RelayUrl, ToBech32, Url}; -use super::{get_git_config_item, save_git_config_item, Repo}; +use super::{Repo, get_git_config_item, save_git_config_item}; #[derive(Debug, PartialEq, Default, Clone)] pub enum ServerProtocol { @@ -961,24 +961,21 @@ mod tests { #[test] fn standard() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: None, - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: None, + user: None, + nip05: None, + }), "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) @@ -987,24 +984,21 @@ mod tests { #[test] fn no_relay() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![], - }, - protocol: None, - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![], + }, + protocol: None, + user: None, + nip05: None, + }), "nostr://npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit", ); Ok(()) @@ -1013,24 +1007,21 @@ mod tests { #[test] fn with_protocol() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: Some(ServerProtocol::Ssh), - user: None, - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: Some(ServerProtocol::Ssh), + user: None, + nip05: None, + }), "nostr://ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) @@ -1039,24 +1030,21 @@ mod tests { #[test] fn with_protocol_and_user() -> Result<()> { assert_eq!( - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - coordinate: Coordinate { - identifier: "ngit".to_string(), - public_key: PublicKey::parse( - "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", - ) - .unwrap(), - kind: nostr_sdk::Kind::GitRepoAnnouncement, - relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], - }, - protocol: Some(ServerProtocol::Ssh), - user: Some("bla".to_string()), - nip05: None, - } - ), + format!("{}", NostrUrlDecoded { + original_string: String::new(), + coordinate: Coordinate { + identifier: "ngit".to_string(), + public_key: PublicKey::parse( + "npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr", + ) + .unwrap(), + kind: nostr_sdk::Kind::GitRepoAnnouncement, + relays: vec![RelayUrl::parse("wss://nos.lol").unwrap()], + }, + protocol: Some(ServerProtocol::Ssh), + user: Some("bla".to_string()), + nip05: None, + }), "nostr://bla@ssh/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/nos.lol/ngit", ); Ok(()) diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index d8564ae..af469d3 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs @@ -1,10 +1,10 @@ use std::{str::FromStr, sync::Arc}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; use nostr_sdk::{ - hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, - PublicKey, RelayUrl, Tag, TagKind, TagStandard, + Event, EventBuilder, EventId, FromBech32, Kind, NostrSigner, PublicKey, RelayUrl, Tag, TagKind, + TagStandard, hashes::sha1::Hash as Sha1Hash, }; use crate::{ @@ -131,15 +131,14 @@ pub async fn generate_patch_event( // code that makes it into the main branch, assuming // the commit id is correct Tag::from_standardized(TagStandard::Reference(commit.to_string())), - Tag::custom( - TagKind::Custom(std::borrow::Cow::Borrowed("alt")), - vec![format!( + Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("alt")), vec![ + format!( "git patch: {}", git_repo .get_commit_message_summary(commit) .unwrap_or_default() - )], - ), + ), + ]), ], if let Some(thread_event_id) = thread_event_id { vec![Tag::from_standardized(nostr_sdk::TagStandard::Event { @@ -203,10 +202,9 @@ pub async fn generate_patch_event( .collect(), vec![ // a fallback is now in place to extract this from the patch - Tag::custom( - TagKind::Custom(std::borrow::Cow::Borrowed("commit")), - vec![commit.to_string()], - ), + Tag::custom(TagKind::Custom(std::borrow::Cow::Borrowed("commit")), vec![ + commit.to_string(), + ]), // this is required as patches cannot be relied upon to include the 'base // commit' Tag::custom( diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs index 4606c22..efe187e 100644 --- a/src/lib/login/existing.rs +++ b/src/lib/login/existing.rs @@ -1,15 +1,15 @@ use std::{str::FromStr, sync::Arc, time::Duration}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::nips::nip46::NostrConnectURI; use nostr_connect::client::NostrConnect; use nostr_sdk::{NostrSigner, PublicKey}; use super::{ + SignerInfo, SignerInfoSource, key_encryption::decrypt_key, print_logged_in_as, - user::{get_user_details, UserRef}, - SignerInfo, SignerInfoSource, + user::{UserRef, get_user_details}, }; #[cfg(not(test))] use crate::client::Client; @@ -18,7 +18,7 @@ use crate::client::MockConnect; use crate::{ cli_interactor::{Interactor, InteractorPrompt, PromptPasswordParms}, client::fetch_public_key, - git::{get_git_config_item, Repo, RepoActions}, + git::{Repo, RepoActions, get_git_config_item}, }; /// load signer from git config and UserProfile from cache or relays diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs index 7cdbde8..635c0b3 100644 --- a/src/lib/login/fresh.rs +++ b/src/lib/login/fresh.rs @@ -1,6 +1,6 @@ use std::{str::FromStr, sync::Arc, time::Duration}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; use dialoguer::theme::{ColorfulTheme, Theme}; use nostr::nips::{nip05, nip46::NostrConnectURI}; @@ -10,11 +10,11 @@ use qrcode::QrCode; use tokio::{signal, sync::Mutex}; use super::{ + SignerInfo, SignerInfoSource, existing::load_existing_login, key_encryption::decrypt_key, print_logged_in_as, - user::{get_user_details, UserRef}, - SignerInfo, SignerInfoSource, + user::{UserRef, get_user_details}, }; #[cfg(not(test))] use crate::client::Client; @@ -25,8 +25,8 @@ use crate::{ Interactor, InteractorPrompt, Printer, PromptChoiceParms, PromptConfirmParms, PromptInputParms, PromptPasswordParms, }, - client::{send_events, Connect}, - git::{remove_git_config_item, save_git_config_item, Repo, RepoActions}, + client::{Connect, send_events}, + git::{Repo, RepoActions, remove_git_config_item, save_git_config_item}, }; pub async fn fresh_login_or_signup( diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs index 0be1e5d..a1c45d5 100644 --- a/src/lib/login/mod.rs +++ b/src/lib/login/mod.rs @@ -79,15 +79,11 @@ fn print_logged_in_as( "failed to find your relay list. consider using another nostr client to create one to enhance your nostr experience." ); } - eprintln!( - "logged in as {}{}", - user_ref.metadata.name, - match source { - SignerInfoSource::CommandLineArguments => " via cli arguments", - SignerInfoSource::GitLocal => " to local repository", - SignerInfoSource::GitGlobal => "", - } - ); + eprintln!("logged in as {}{}", user_ref.metadata.name, match source { + SignerInfoSource::CommandLineArguments => " via cli arguments", + SignerInfoSource::GitLocal => " to local repository", + SignerInfoSource::GitGlobal => "", + }); Ok(()) } diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs index de4a2d9..107e765 100644 --- a/src/lib/login/user.rs +++ b/src/lib/login/user.rs @@ -1,6 +1,6 @@ use std::{collections::HashSet, path::Path}; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use nostr::PublicKey; use nostr_sdk::{Alphabet, JsonUtil, Kind, SingleLetterTag, Timestamp, ToBech32}; use serde::{self, Deserialize, Serialize}; @@ -9,7 +9,7 @@ use serde::{self, Deserialize, Serialize}; use crate::client::Client; #[cfg(test)] use crate::client::MockConnect; -use crate::client::{get_event_from_global_cache, Connect}; +use crate::client::{Connect, get_event_from_global_cache}; #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] pub struct UserRef { diff --git a/src/lib/mod.rs b/src/lib/mod.rs index 6e6f6fe..2072a80 100644 --- a/src/lib/mod.rs +++ b/src/lib/mod.rs @@ -6,7 +6,7 @@ pub mod login; pub mod repo_ref; pub mod repo_state; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use directories::ProjectDirs; pub fn get_dirs() -> Result { diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 5d6f4eb..a9d1186 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs @@ -6,9 +6,9 @@ use std::{ sync::Arc, }; -use anyhow::{bail, Context, Result}; +use anyhow::{Context, Result, bail}; use console::Style; -use nostr::{nips::nip01::Coordinate, FromBech32, PublicKey, Tag, TagStandard, ToBech32}; +use nostr::{FromBech32, PublicKey, Tag, TagStandard, ToBech32, nips::nip01::Coordinate}; use nostr_sdk::{Kind, NostrSigner, RelayUrl, Timestamp}; use serde::{Deserialize, Serialize}; @@ -18,10 +18,10 @@ use crate::{ cli_interactor::{ Interactor, InteractorPrompt, PromptChoiceParms, PromptConfirmParms, PromptInputParms, }, - client::{consolidate_fetch_reports, get_repo_ref_from_cache, sign_event, Connect}, + client::{Connect, consolidate_fetch_reports, get_repo_ref_from_cache, sign_event}, git::{ - nostr_url::{use_nip05_git_config_cache_to_find_nip05_from_public_key, NostrUrlDecoded}, Repo, RepoActions, + nostr_url::{NostrUrlDecoded, use_nip05_git_config_cache_to_find_nip05_from_public_key}, }, login::user::get_user_details, }; @@ -237,20 +237,17 @@ impl RepoRef { pub fn to_nostr_git_url(&self, git_repo: &Option<&Repo>) -> String { let c = self.coordinate_with_hint(); - format!( - "{}", - NostrUrlDecoded { - original_string: String::new(), - nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( - &c.public_key, - git_repo, - ) - .unwrap_or_default(), - coordinate: c, - protocol: None, - user: None, - } - ) + format!("{}", NostrUrlDecoded { + original_string: String::new(), + nip05: use_nip05_git_config_cache_to_find_nip05_from_public_key( + &c.public_key, + git_repo, + ) + .unwrap_or_default(), + coordinate: c, + protocol: None, + user: None, + }) } } @@ -521,14 +518,11 @@ pub fn save_repo_config_to_yaml( .context("failed to convert public key into npub")?, ); } - serde_yaml::to_writer( - file, - &RepoConfigYaml { - identifier: Some(identifier), - maintainers: maintainers_npubs, - relays, - }, - ) + serde_yaml::to_writer(file, &RepoConfigYaml { + identifier: Some(identifier), + maintainers: maintainers_npubs, + relays, + }) .context("failed to write maintainers to maintainers.yaml file serde_yaml") } -- cgit v1.2.3