From 52a1be1b7cfd66401fd99dcbd24c0e09327bebff Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Sat, 21 Sep 2024 21:52:42 +0000 Subject: [PATCH] chore: cargo fmt everything --- spr/src/commands/init.rs | 4 +++- spr/src/commands/land.rs | 4 ++-- spr/src/commands/list.rs | 4 +++- spr/src/git.rs | 4 +++- spr/src/github.rs | 35 +++++++++++++++++------------------ spr/src/main.rs | 13 +++++-------- 6 files changed, 33 insertions(+), 31 deletions(-) diff --git a/spr/src/commands/init.rs b/spr/src/commands/init.rs index c44748d..28b80d8 100644 --- a/spr/src/commands/init.rs +++ b/spr/src/commands/init.rs @@ -225,7 +225,9 @@ fn validate_branch_prefix(branch_prefix: &str) -> Result<()> { } if branch_prefix.contains("//") || branch_prefix.starts_with('/') { - return Err(Error::new("Branch prefix contains multiple consecutive slashes or starts with slash.")); + return Err(Error::new( + "Branch prefix contains multiple consecutive slashes or starts with slash.", + )); } if branch_prefix.contains("@{") { diff --git a/spr/src/commands/land.rs b/spr/src/commands/land.rs index 22f113e..24c33b3 100644 --- a/spr/src/commands/land.rs +++ b/spr/src/commands/land.rs @@ -275,10 +275,10 @@ pub async fn land( if git.get_tree_oid_for_commit(merge_commit)? != our_tree_oid { return Err(Error::new(formatdoc!( - "This commit has been updated and/or rebased since the pull + "This commit has been updated and/or rebased since the pull request was last updated. Please run `spr diff` to update the pull request and then try `spr land` again!" - ))); + ))); } }; diff --git a/spr/src/commands/list.rs b/spr/src/commands/list.rs index 54acc85..2b728cb 100644 --- a/spr/src/commands/list.rs +++ b/spr/src/commands/list.rs @@ -41,7 +41,9 @@ fn print_pr_info( let term = console::Term::stdout(); for pr in response_body.data?.search.nodes? { let pr = match pr { - Some(crate::commands::list::search_query::SearchQuerySearchNodes::PullRequest(pr)) => pr, + Some(crate::commands::list::search_query::SearchQuerySearchNodes::PullRequest(pr)) => { + pr + } _ => continue, }; let dummy: String; diff --git a/spr/src/git.rs b/spr/src/git.rs index 6b62a89..3aad0a6 100644 --- a/spr/src/git.rs +++ b/spr/src/git.rs @@ -36,7 +36,9 @@ pub struct Git { impl Git { pub fn new(repo: git2::Repository) -> Self { Self { - hooks: std::sync::Arc::new(std::sync::Mutex::new(git2_ext::hooks::Hooks::with_repo(&repo).unwrap())), + hooks: std::sync::Arc::new(std::sync::Mutex::new( + git2_ext::hooks::Hooks::with_repo(&repo).unwrap(), + )), repo: std::sync::Arc::new(std::sync::Mutex::new(repo)), } } diff --git a/spr/src/github.rs b/spr/src/github.rs index 15737b5..01ab8a7 100644 --- a/spr/src/github.rs +++ b/spr/src/github.rs @@ -130,14 +130,8 @@ type GitObjectID = String; pub struct PullRequestMergeabilityQuery; impl GitHub { - pub fn new( - config: crate::config::Config, - git: crate::git::Git, - ) -> Self { - Self { - config, - git, - } + pub fn new(config: crate::config::Config, git: crate::git::Git) -> Self { + Self { config, git } } pub async fn get_github_user(login: String) -> Result { @@ -159,10 +153,7 @@ impl GitHub { } pub async fn get_pull_request(self, number: u64) -> Result { - let GitHub { - config, - git, - } = self; + let GitHub { config, git } = self; let variables = pull_request_query::Variables { name: config.repo.clone(), @@ -226,7 +217,9 @@ impl GitHub { let user_name = review.author.as_ref()?.login.clone(); let status = match review.state { pull_request_query::PullRequestReviewState::APPROVED => ReviewStatus::Approved, - pull_request_query::PullRequestReviewState::CHANGES_REQUESTED => ReviewStatus::Rejected, + pull_request_query::PullRequestReviewState::CHANGES_REQUESTED => { + ReviewStatus::Rejected + } _ => ReviewStatus::Requested, }; Some((user_name, status)) @@ -234,9 +227,15 @@ impl GitHub { .collect(); let review_status = match pr.review_decision { - Some(pull_request_query::PullRequestReviewDecision::APPROVED) => Some(ReviewStatus::Approved), - Some(pull_request_query::PullRequestReviewDecision::CHANGES_REQUESTED) => Some(ReviewStatus::Rejected), - Some(pull_request_query::PullRequestReviewDecision::REVIEW_REQUIRED) => Some(ReviewStatus::Requested), + Some(pull_request_query::PullRequestReviewDecision::APPROVED) => { + Some(ReviewStatus::Approved) + } + Some(pull_request_query::PullRequestReviewDecision::CHANGES_REQUESTED) => { + Some(ReviewStatus::Rejected) + } + Some(pull_request_query::PullRequestReviewDecision::REVIEW_REQUIRED) => { + Some(ReviewStatus::Requested) + } _ => None, }; @@ -421,8 +420,8 @@ impl GitHub { _ => None, }, merge_commit: pr - .merge_commit - .and_then(|sha| git2::Oid::from_str(&sha.oid).ok()), + .merge_commit + .and_then(|sha| git2::Oid::from_str(&sha.oid).ok()), }) } } diff --git a/spr/src/main.rs b/spr/src/main.rs index 20a5022..5c2638c 100644 --- a/spr/src/main.rs +++ b/spr/src/main.rs @@ -84,9 +84,7 @@ enum Commands { #[derive(Debug, thiserror::Error)] pub enum OptionsError { - #[error( - "GitHub repository must be given as 'OWNER/REPO', but given value was '{0}'" - )] + #[error("GitHub repository must be given as 'OWNER/REPO', but given value was '{0}'")] InvalidRepository(String), } @@ -137,7 +135,9 @@ pub async fn spr() -> Result<()> { let branch_prefix = cli .branch_prefix .map_or_else(|| git_config.get_string("spr.branchPrefix"), Ok) - .map_err(|e| Error::new(format!("spr.branchPrefix must be configured: {e:?}")))?; + .map_err(|e| { + Error::new(format!("spr.branchPrefix must be configured: {e:?}")) + })?; let require_approval = git_config .get_bool("spr.requireApproval") .ok() @@ -185,10 +185,7 @@ pub async fn spr() -> Result<()> { format!("Bearer {}", github_auth_token).parse()?, ); - let mut gh = spr::github::GitHub::new( - config.clone(), - git.clone(), - ); + let mut gh = spr::github::GitHub::new(config.clone(), git.clone()); match cli.command { Commands::Diff(opts) => {