diff --git a/src/app/mod.rs b/src/app/mod.rs index 0031579..a74aecc 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -192,10 +192,7 @@ impl App { if auth_user.is_none() && token.is_some() { log::warn!("stored token rejected by GitHub, clearing it"); let _ = auth::clear_token(); - github = crate::provider::create_provider( - crate::provider::ProviderKind::GitHub, - None, - )?; + github = crate::provider::create_provider(crate::provider::ProviderKind::GitHub, None)?; } if account.preferred_clone_dir.trim().is_empty() { @@ -211,9 +208,7 @@ impl App { "Stored token is invalid. Press t to set a new one or continue anonymously." .to_string() } - None => { - "No token set. Press t to save one or continue anonymously.".to_string() - } + None => "No token set. Press t to save one or continue anonymously.".to_string(), }; Ok(Self { @@ -430,11 +425,8 @@ mod tests { fn test_app() -> App { App { - github: crate::provider::create_provider( - crate::provider::ProviderKind::GitHub, - None, - ) - .expect("client"), + github: crate::provider::create_provider(crate::provider::ProviderKind::GitHub, None) + .expect("client"), account: crate::config::AccountConfig { preferred_clone_dir: ".".to_string(), last_branch_by_repo: Default::default(), @@ -642,11 +634,8 @@ mod tests { #[test] fn lazy_tree_progress_advances_limit() { let mut app = App { - github: crate::provider::create_provider( - crate::provider::ProviderKind::GitHub, - None, - ) - .expect("client"), + github: crate::provider::create_provider(crate::provider::ProviderKind::GitHub, None) + .expect("client"), account: crate::config::AccountConfig { preferred_clone_dir: ".".to_string(), last_branch_by_repo: Default::default(), diff --git a/src/app/theme.rs b/src/app/theme.rs index 1dc43d0..1f3a032 100644 --- a/src/app/theme.rs +++ b/src/app/theme.rs @@ -229,7 +229,11 @@ mod tests { } // Verify load_theme_by_name returns Berlin let berlin = load_theme_by_name("Berlin"); - assert_eq!(berlin.palette.len(), 16, "Berlin palette should have 16 entries"); + assert_eq!( + berlin.palette.len(), + 16, + "Berlin palette should have 16 entries" + ); assert_eq!(berlin.palette[0], [0, 0, 0], "first entry should be black"); // Apply Berlin theme init_theme(&berlin); diff --git a/src/cli/git.rs b/src/cli/git.rs index 4733dfc..211dd24 100644 --- a/src/cli/git.rs +++ b/src/cli/git.rs @@ -619,10 +619,8 @@ pub fn merge(branch: &str) -> Result<()> { pub fn download_file(repo: &str, path: &str, r#ref: Option<&str>, out: &PathBuf) -> Result<()> { let token = auth::load_token()?; - let client = crate::provider::create_provider( - crate::provider::ProviderKind::GitHub, - token.as_deref(), - )?; + let client = + crate::provider::create_provider(crate::provider::ProviderKind::GitHub, token.as_deref())?; let bytes = match r#ref { Some(branch) if !branch.trim().is_empty() => { diff --git a/src/cli/helpers.rs b/src/cli/helpers.rs index 393356c..638f8ad 100644 --- a/src/cli/helpers.rs +++ b/src/cli/helpers.rs @@ -114,12 +114,12 @@ pub fn handle_api_error(full_name: &str, e: &anyhow::Error) -> String { .downcast_ref::() .map(|gh_err| match gh_err { GitHubError::Api { status, body } if *status == 404 || body.contains("Not Found") => { - format!("repository '{full_name}' not found on GitHub") - } - GitHubError::Unauthorized => { - "authentication required — run 'gitnapse auth set' or 'gitnapse auth oauth login'" - .to_string() - } + format!("repository '{full_name}' not found on GitHub") + } + GitHubError::Unauthorized => { + "authentication required — run 'gitnapse auth set' or 'gitnapse auth oauth login'" + .to_string() + } GitHubError::RateLimited { remaining: _, reset, diff --git a/src/config/keybindings.rs b/src/config/keybindings.rs index 523310c..2dabd26 100644 --- a/src/config/keybindings.rs +++ b/src/config/keybindings.rs @@ -16,16 +16,31 @@ fn parse_keybinding(s: &str) -> Option { let s = s.trim(); if let Some(rest) = s.strip_prefix("Ctrl+").or_else(|| s.strip_prefix("ctrl+")) { let code = str_to_keycode(rest)?; - Some(BoundKey { code, modifiers: KeyModifiers::CONTROL }) - } else if let Some(rest) = s.strip_prefix("Shift+").or_else(|| s.strip_prefix("shift+")) { + Some(BoundKey { + code, + modifiers: KeyModifiers::CONTROL, + }) + } else if let Some(rest) = s + .strip_prefix("Shift+") + .or_else(|| s.strip_prefix("shift+")) + { let code = str_to_keycode(rest)?; - Some(BoundKey { code, modifiers: KeyModifiers::SHIFT }) + Some(BoundKey { + code, + modifiers: KeyModifiers::SHIFT, + }) } else if let Some(rest) = s.strip_prefix("Alt+").or_else(|| s.strip_prefix("alt+")) { let code = str_to_keycode(rest)?; - Some(BoundKey { code, modifiers: KeyModifiers::ALT }) + Some(BoundKey { + code, + modifiers: KeyModifiers::ALT, + }) } else { let code = str_to_keycode(s)?; - Some(BoundKey { code, modifiers: KeyModifiers::NONE }) + Some(BoundKey { + code, + modifiers: KeyModifiers::NONE, + }) } } diff --git a/src/github/mod.rs b/src/github/mod.rs index 2cc4e45..3ba9190 100644 --- a/src/github/mod.rs +++ b/src/github/mod.rs @@ -11,8 +11,8 @@ const REQUEST_TIMEOUT: Duration = Duration::from_secs(30); mod ci; mod compare; mod content; -mod prs; mod provider_impl; +mod prs; mod releases; mod repos; diff --git a/src/github/provider_impl.rs b/src/github/provider_impl.rs index 85238ab..971168a 100644 --- a/src/github/provider_impl.rs +++ b/src/github/provider_impl.rs @@ -29,7 +29,11 @@ impl GitProvider for GitHubClient { self.fetch_repo_tree(full_name, branch).map_err(Into::into) } - fn fetch_starred_repos(&self, page: u32, per_page: u8) -> Result> { + fn fetch_starred_repos( + &self, + page: u32, + per_page: u8, + ) -> Result> { self.fetch_starred_repos(page, per_page).map_err(Into::into) } @@ -142,22 +146,12 @@ impl GitProvider for GitHubClient { Ok(()) } - fn update_pull_request( - &self, - full_name: &str, - number: u64, - state: &str, - ) -> Result<()> { + fn update_pull_request(&self, full_name: &str, number: u64, state: &str) -> Result<()> { let _ = self.update_pull_request(full_name, number, state)?; Ok(()) } - fn create_pull_request_comment( - &self, - full_name: &str, - number: u64, - body: &str, - ) -> Result<()> { + fn create_pull_request_comment(&self, full_name: &str, number: u64, body: &str) -> Result<()> { let _ = self.create_pull_request_comment(full_name, number, body)?; Ok(()) } @@ -190,7 +184,8 @@ impl GitProvider for GitHubClient { base: &str, head: &str, ) -> Result { - self.fetch_compare(full_name, base, head).map_err(Into::into) + self.fetch_compare(full_name, base, head) + .map_err(Into::into) } fn fetch_check_runs( @@ -211,11 +206,7 @@ impl GitProvider for GitHubClient { .map_err(Into::into) } - fn fetch_releases( - &self, - full_name: &str, - per_page: u8, - ) -> Result> { + fn fetch_releases(&self, full_name: &str, per_page: u8) -> Result> { self.fetch_releases(full_name, per_page).map_err(Into::into) } diff --git a/src/main.rs b/src/main.rs index 23334b0..4053131 100644 --- a/src/main.rs +++ b/src/main.rs @@ -106,7 +106,11 @@ fn main() -> Result<()> { } fn dispatch(cmd: Option) -> Result<()> { - use Command::{Run, DownloadFile, Clone, Commit, Push, Pull, Fetch, Checkout, Diff, Stash, Tag, Status, Log, Branch, Reset, Pr, Issue, Ci, Compare, Remote, Config, Merge, Release, Repo, Search, Auth}; + use Command::{ + Auth, Branch, Checkout, Ci, Clone, Commit, Compare, Config, Diff, DownloadFile, Fetch, + Issue, Log, Merge, Pr, Pull, Push, Release, Remote, Repo, Reset, Run, Search, Stash, + Status, Tag, + }; match cmd { Some(Run(args)) => app::run_with_options(args.into()), Some(DownloadFile(args)) => { @@ -141,7 +145,7 @@ fn dispatch(cmd: Option) -> Result<()> { } fn dispatch_stash(action: cli::StashAction) -> Result<()> { - use cli::StashAction::{Push, Pop, List}; + use cli::StashAction::{List, Pop, Push}; match action { Push { message } => cli::stash_push(message.as_deref()), Pop => cli::stash_pop(), @@ -150,16 +154,20 @@ fn dispatch_stash(action: cli::StashAction) -> Result<()> { } fn dispatch_tag(action: cli::TagAction) -> Result<()> { - use cli::TagAction::{List, Create, Delete}; + use cli::TagAction::{Create, Delete, List}; match action { List { pattern } => cli::tag_list(pattern.as_deref()), - Create { name, message, target } => cli::tag_create(&name, message.as_deref(), target.as_deref()), + Create { + name, + message, + target, + } => cli::tag_create(&name, message.as_deref(), target.as_deref()), Delete { name } => cli::tag_delete(&name), } } fn dispatch_pr(action: cli::PrAction) -> Result<()> { - use cli::PrAction::{List, Create, Merge}; + use cli::PrAction::{Create, List, Merge}; match action { List(a) => cli::pr_list(&a.repo, &a.state), Create(a) => cli::pr_create(&a.repo, &a.title, &a.head, &a.base, a.body.as_deref()), @@ -168,7 +176,7 @@ fn dispatch_pr(action: cli::PrAction) -> Result<()> { } fn dispatch_issue(action: cli::IssueAction) -> Result<()> { - use cli::IssueAction::{List, Create, Close}; + use cli::IssueAction::{Close, Create, List}; match action { List(a) => cli::issue_list(&a.repo, &a.state), Create(a) => cli::issue_create(&a.repo, &a.title, a.body.as_deref()), @@ -177,7 +185,7 @@ fn dispatch_issue(action: cli::IssueAction) -> Result<()> { } fn dispatch_remote(action: cli::RemoteAction) -> Result<()> { - use cli::RemoteAction::{List, Add, Remove, Rename}; + use cli::RemoteAction::{Add, List, Remove, Rename}; match action { List => cli::remote_list(), Add(a) => cli::remote_add(&a.name, &a.url), @@ -187,7 +195,7 @@ fn dispatch_remote(action: cli::RemoteAction) -> Result<()> { } fn dispatch_config(action: cli::ConfigAction) -> Result<()> { - use cli::ConfigAction::{Get, Set, List}; + use cli::ConfigAction::{Get, List, Set}; match action { Get(a) => cli::config_get(&a.key), Set(a) => cli::config_set(&a.key, &a.value), @@ -196,10 +204,16 @@ fn dispatch_config(action: cli::ConfigAction) -> Result<()> { } fn dispatch_release(action: cli::ReleaseAction) -> Result<()> { - use cli::ReleaseAction::{List, Create}; + use cli::ReleaseAction::{Create, List}; match action { List(a) => cli::release_list(&a.repo), - Create(a) => cli::release_create(&a.repo, &a.tag_name, a.name.as_deref(), a.body.as_deref(), a.prerelease), + Create(a) => cli::release_create( + &a.repo, + &a.tag_name, + a.name.as_deref(), + a.body.as_deref(), + a.prerelease, + ), } } @@ -211,7 +225,7 @@ fn dispatch_repo(action: cli::RepoAction) -> Result<()> { } fn dispatch_auth(action: cli::AuthAction) -> Result<()> { - use cli::AuthAction::{Set, Clear, Status, Oauth}; + use cli::AuthAction::{Clear, Oauth, Set, Status}; match action { Set { token } => auth::set_token_cli(token), Clear => auth::clear_token_cli(), @@ -223,7 +237,11 @@ fn dispatch_auth(action: cli::AuthAction) -> Result<()> { fn dispatch_oauth(action: cli::OauthAction) -> Result<()> { use cli::OauthAction::{Login, Status}; match action { - Login { client_id, scope, timeout_secs } => oauth::oauth_device_login_cli(client_id, scope, timeout_secs), + Login { + client_id, + scope, + timeout_secs, + } => oauth::oauth_device_login_cli(client_id, scope, timeout_secs), Status => oauth::oauth_status_cli(), } } diff --git a/src/oauth.rs b/src/oauth.rs index 29eb761..bf7d2bb 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -168,10 +168,8 @@ pub fn oauth_status_cli() -> Result<()> { return Ok(()); } - let client = crate::provider::create_provider( - crate::provider::ProviderKind::GitHub, - token.as_deref(), - )?; + let client = + crate::provider::create_provider(crate::provider::ProviderKind::GitHub, token.as_deref())?; let user = client.fetch_authenticated_user()?; let authenticated = user.is_some(); diff --git a/src/provider.rs b/src/provider.rs index 10db2ff..130495e 100644 --- a/src/provider.rs +++ b/src/provider.rs @@ -1,7 +1,6 @@ use crate::models::{ - CheckRun, CommitInfo, CompareResponse, Issue, MergeResponse, PullRequest, - PullRequestDetail, PullRequestReview, Release, RepoNode, RepoSummary, ReviewComment, - WorkflowRun, + CheckRun, CommitInfo, CompareResponse, Issue, MergeResponse, PullRequest, PullRequestDetail, + PullRequestReview, Release, RepoNode, RepoSummary, ReviewComment, WorkflowRun, }; use anyhow::Result; use std::sync::Arc; @@ -77,11 +76,7 @@ pub trait GitProvider: Send + Sync { state: &str, per_page: u8, ) -> Result>; - fn fetch_pull_request_detail( - &self, - full_name: &str, - number: u64, - ) -> Result; + fn fetch_pull_request_detail(&self, full_name: &str, number: u64) -> Result; fn fetch_pull_request_reviews( &self, full_name: &str, @@ -92,11 +87,7 @@ pub trait GitProvider: Send + Sync { full_name: &str, number: u64, ) -> Result>; - fn fetch_pull_request_commits( - &self, - full_name: &str, - number: u64, - ) -> Result>; + fn fetch_pull_request_commits(&self, full_name: &str, number: u64) -> Result>; fn merge_pull_request( &self, full_name: &str, @@ -111,18 +102,8 @@ pub trait GitProvider: Send + Sync { body: &str, event: &str, ) -> Result<()>; - fn update_pull_request( - &self, - full_name: &str, - number: u64, - state: &str, - ) -> Result<()>; - fn create_pull_request_comment( - &self, - full_name: &str, - number: u64, - body: &str, - ) -> Result<()>; + fn update_pull_request(&self, full_name: &str, number: u64, state: &str) -> Result<()>; + fn create_pull_request_comment(&self, full_name: &str, number: u64, body: &str) -> Result<()>; fn create_pull_request( &self, full_name: &str, @@ -138,12 +119,7 @@ pub trait GitProvider: Send + Sync { branch: &str, per_page: u8, ) -> Result>; - fn fetch_compare( - &self, - full_name: &str, - base: &str, - head: &str, - ) -> Result; + fn fetch_compare(&self, full_name: &str, base: &str, head: &str) -> Result; fn fetch_check_runs(&self, full_name: &str, ref_: &str) -> Result>; fn fetch_workflow_runs( @@ -175,10 +151,7 @@ pub trait GitProvider: Send + Sync { } /// Factory: create a provider instance for the given kind and token. -pub fn create_provider( - kind: ProviderKind, - token: Option<&str>, -) -> Result> { +pub fn create_provider(kind: ProviderKind, token: Option<&str>) -> Result> { match kind { ProviderKind::GitHub | ProviderKind::Other => { let client = crate::github::GitHubClient::new(token)?; diff --git a/src/runtime.rs b/src/runtime.rs index 34827bc..33cdffb 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -14,10 +14,8 @@ pub fn get_runtime() -> &'static Runtime { /// Install the rustls crypto provider (required before any TLS connection). /// Safe to call multiple times – subsequent calls are no-ops. pub fn ensure_crypto_provider() { - if rustls::crypto::CryptoProvider::install_default( - rustls::crypto::ring::default_provider(), - ) - .is_err() + if rustls::crypto::CryptoProvider::install_default(rustls::crypto::ring::default_provider()) + .is_err() { log::warn!("could not install rustls crypto provider (may already be set)"); }