diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 16:21:38 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-12 16:21:38 +0000 |
| commit | 90fb2bbb72be8a371faa5f2adce728a5401b73fb (patch) | |
| tree | 503c5ef975fecc662110984713d7aa208b189e61 /src/bin/ngit | |
| parent | 1be46b4fd7a78ce418765ef5467823b7ea5e60eb (diff) | |
style: apply cargo clippy and fmt fixes
Reorganize imports and fix formatting issues flagged by clippy and rustfmt.
Diffstat (limited to 'src/bin/ngit')
| -rw-r--r-- | src/bin/ngit/sub_commands/apply.rs | 32 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 14 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/list.rs | 20 |
3 files changed, 37 insertions, 29 deletions
diff --git a/src/bin/ngit/sub_commands/apply.rs b/src/bin/ngit/sub_commands/apply.rs index fd9eae3..4ed6caa 100644 --- a/src/bin/ngit/sub_commands/apply.rs +++ b/src/bin/ngit/sub_commands/apply.rs | |||
| @@ -4,14 +4,18 @@ use std::{ | |||
| 4 | }; | 4 | }; |
| 5 | 5 | ||
| 6 | use anyhow::{Context, Result, bail}; | 6 | use anyhow::{Context, Result, bail}; |
| 7 | use ngit::client::get_all_proposal_patch_pr_pr_update_events_from_cache; | 7 | use ngit::{ |
| 8 | use ngit::git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors; | 8 | client::get_all_proposal_patch_pr_pr_update_events_from_cache, |
| 9 | git_events::get_pr_tip_event_or_most_recent_patch_with_ancestors, | ||
| 10 | }; | ||
| 9 | use nostr::nips::nip19::Nip19; | 11 | use nostr::nips::nip19::Nip19; |
| 10 | use nostr_sdk::{EventId, FromBech32}; | 12 | use nostr_sdk::{EventId, FromBech32}; |
| 11 | 13 | ||
| 12 | use crate::client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}; | 14 | use crate::{ |
| 13 | use crate::git::{Repo, RepoActions}; | 15 | client::{Client, Connect, fetching_with_report, get_repo_ref_from_cache}, |
| 14 | use crate::repo_ref::get_repo_coordinates_when_remote_unknown; | 16 | git::{Repo, RepoActions}, |
| 17 | repo_ref::get_repo_coordinates_when_remote_unknown, | ||
| 18 | }; | ||
| 15 | 19 | ||
| 16 | fn run_git_fetch(remote_name: &str) -> Result<()> { | 20 | fn run_git_fetch(remote_name: &str) -> Result<()> { |
| 17 | println!("fetching from {remote_name}..."); | 21 | println!("fetching from {remote_name}..."); |
| @@ -55,11 +59,8 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { | |||
| 55 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; | 59 | let repo_ref = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await?; |
| 56 | 60 | ||
| 57 | let proposals_and_revisions: Vec<nostr::Event> = | 61 | let proposals_and_revisions: Vec<nostr::Event> = |
| 58 | ngit::client::get_proposals_and_revisions_from_cache( | 62 | ngit::client::get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) |
| 59 | git_repo_path, | 63 | .await?; |
| 60 | repo_ref.coordinates(), | ||
| 61 | ) | ||
| 62 | .await?; | ||
| 63 | 64 | ||
| 64 | let proposal = proposals_and_revisions | 65 | let proposal = proposals_and_revisions |
| 65 | .iter() | 66 | .iter() |
| @@ -79,10 +80,13 @@ pub async fn launch(id: &str, stdout: bool) -> Result<()> { | |||
| 79 | let patches = get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone()) | 80 | let patches = get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone()) |
| 80 | .context("failed to find any PR or patch events on this proposal")?; | 81 | .context("failed to find any PR or patch events on this proposal")?; |
| 81 | 82 | ||
| 82 | if patches | 83 | if patches.iter().any(|e| { |
| 83 | .iter() | 84 | [ |
| 84 | .any(|e| [ngit::git_events::KIND_PULL_REQUEST, ngit::git_events::KIND_PULL_REQUEST_UPDATE].contains(&e.kind)) | 85 | ngit::git_events::KIND_PULL_REQUEST, |
| 85 | { | 86 | ngit::git_events::KIND_PULL_REQUEST_UPDATE, |
| 87 | ] | ||
| 88 | .contains(&e.kind) | ||
| 89 | }) { | ||
| 86 | bail!( | 90 | bail!( |
| 87 | "this proposal uses PR format (not patches). Use `ngit checkout {}` instead.", | 91 | "this proposal uses PR format (not patches). Use `ngit checkout {}` instead.", |
| 88 | event_id.to_hex() | 92 | event_id.to_hex() |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 2f34ecb..087fa14 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -231,7 +231,10 @@ fn validate_hashtag(s: &str) -> Result<String> { | |||
| 231 | if trimmed.is_empty() { | 231 | if trimmed.is_empty() { |
| 232 | bail!("hashtag cannot be empty"); | 232 | bail!("hashtag cannot be empty"); |
| 233 | } | 233 | } |
| 234 | if !trimmed.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-') { | 234 | if !trimmed |
| 235 | .chars() | ||
| 236 | .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-') | ||
| 237 | { | ||
| 235 | bail!("hashtag can only contain lowercase letters (a-z), digits (0-9), and hyphens (-)"); | 238 | bail!("hashtag can only contain lowercase letters (a-z), digits (0-9), and hyphens (-)"); |
| 236 | } | 239 | } |
| 237 | if trimmed.starts_with('-') || trimmed.ends_with('-') { | 240 | if trimmed.starts_with('-') || trimmed.ends_with('-') { |
| @@ -246,15 +249,10 @@ fn validate_hashtag(s: &str) -> Result<String> { | |||
| 246 | /// Resolve the `hashtags` field from args or existing announcement. | 249 | /// Resolve the `hashtags` field from args or existing announcement. |
| 247 | fn resolve_hashtags(args_hashtag: &[String], state: &InitState) -> Result<Vec<String>> { | 250 | fn resolve_hashtags(args_hashtag: &[String], state: &InitState) -> Result<Vec<String>> { |
| 248 | if !args_hashtag.is_empty() { | 251 | if !args_hashtag.is_empty() { |
| 249 | return args_hashtag | 252 | return args_hashtag.iter().map(|h| validate_hashtag(h)).collect(); |
| 250 | .iter() | ||
| 251 | .map(|h| validate_hashtag(h)) | ||
| 252 | .collect(); | ||
| 253 | } | 253 | } |
| 254 | if let Some(rr) = state.repo_ref() { | 254 | if let Some(rr) = state.repo_ref() { |
| 255 | return Ok( | 255 | return Ok(latest_event_repo_ref(rr).map_or_else(|| rr.hashtags.clone(), |lr| lr.hashtags)); |
| 256 | latest_event_repo_ref(rr).map_or_else(|| rr.hashtags.clone(), |lr| lr.hashtags), | ||
| 257 | ); | ||
| 258 | } | 256 | } |
| 259 | Ok(vec![]) | 257 | Ok(vec![]) |
| 260 | } | 258 | } |
diff --git a/src/bin/ngit/sub_commands/list.rs b/src/bin/ngit/sub_commands/list.rs index 6d78a1f..b008cf0 100644 --- a/src/bin/ngit/sub_commands/list.rs +++ b/src/bin/ngit/sub_commands/list.rs | |||
| @@ -1,5 +1,7 @@ | |||
| 1 | use std::{ | 1 | use std::{ |
| 2 | collections::HashSet, io::Write, ops::Add, | 2 | collections::HashSet, |
| 3 | io::Write, | ||
| 4 | ops::Add, | ||
| 3 | process::{Command, Stdio}, | 5 | process::{Command, Stdio}, |
| 4 | }; | 6 | }; |
| 5 | 7 | ||
| @@ -16,9 +18,11 @@ use ngit::{ | |||
| 16 | }, | 18 | }, |
| 17 | repo_ref::{RepoRef, is_grasp_server_in_list}, | 19 | repo_ref::{RepoRef, is_grasp_server_in_list}, |
| 18 | }; | 20 | }; |
| 19 | use nostr::filter::{Alphabet, SingleLetterTag}; | 21 | use nostr::{ |
| 20 | use nostr::nips::nip19::Nip19; | 22 | FromBech32, ToBech32, |
| 21 | use nostr::{FromBech32, ToBech32}; | 23 | filter::{Alphabet, SingleLetterTag}, |
| 24 | nips::nip19::Nip19, | ||
| 25 | }; | ||
| 22 | use nostr_sdk::Kind; | 26 | use nostr_sdk::Kind; |
| 23 | 27 | ||
| 24 | use crate::{ | 28 | use crate::{ |
| @@ -242,8 +246,7 @@ fn show_proposal_details( | |||
| 242 | json: bool, | 246 | json: bool, |
| 243 | ) -> Result<()> { | 247 | ) -> Result<()> { |
| 244 | let target_id = if event_id_or_nevent.starts_with("nevent") { | 248 | let target_id = if event_id_or_nevent.starts_with("nevent") { |
| 245 | let nip19 = Nip19::from_bech32(event_id_or_nevent) | 249 | let nip19 = Nip19::from_bech32(event_id_or_nevent).context("failed to parse nevent")?; |
| 246 | .context("failed to parse nevent")?; | ||
| 247 | match nip19 { | 250 | match nip19 { |
| 248 | Nip19::EventId(id) => id, | 251 | Nip19::EventId(id) => id, |
| 249 | Nip19::Event(event) => event.event_id, | 252 | Nip19::Event(event) => event.event_id, |
| @@ -294,7 +297,10 @@ fn show_proposal_details( | |||
| 294 | } | 297 | } |
| 295 | 298 | ||
| 296 | println!(); | 299 | println!(); |
| 297 | println!("To checkout: ngit checkout {}", &proposal.id.to_string()[..7]); | 300 | println!( |
| 301 | "To checkout: ngit checkout {}", | ||
| 302 | &proposal.id.to_string()[..7] | ||
| 303 | ); | ||
| 298 | println!("To apply: ngit apply {}", &proposal.id.to_string()[..7]); | 304 | println!("To apply: ngit apply {}", &proposal.id.to_string()[..7]); |
| 299 | 305 | ||
| 300 | Ok(()) | 306 | Ok(()) |