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/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 +++++------- 12 files changed, 213 insertions(+), 266 deletions(-) (limited to 'src/lib') 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