diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 14:31:32 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-01 15:22:38 +0000 |
| commit | d2ac69816567f092fe0d4661723bc43778cb481b (patch) | |
| tree | e8b51b61a6a7b0ab1a214adebe4e237143b01f0b /src/nostr | |
| parent | 7a78815e29b01c83f3d0ec195ba717a2eba8cd37 (diff) | |
fix cargo clippy and fmt warnings
Diffstat (limited to 'src/nostr')
| -rw-r--r-- | src/nostr/builder.rs | 14 | ||||
| -rw-r--r-- | src/nostr/events.rs | 18 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs index 8e9926a..97fd17e 100644 --- a/src/nostr/builder.rs +++ b/src/nostr/builder.rs | |||
| @@ -51,7 +51,7 @@ impl Nip34WritePolicy { | |||
| 51 | /// Create a bare git repository if it doesn't exist | 51 | /// Create a bare git repository if it doesn't exist |
| 52 | /// Path format: <git_data_path>/<npub>/<identifier>.git | 52 | /// Path format: <git_data_path>/<npub>/<identifier>.git |
| 53 | fn ensure_bare_repository(&self, announcement: &RepositoryAnnouncement) -> Result<(), String> { | 53 | fn ensure_bare_repository(&self, announcement: &RepositoryAnnouncement) -> Result<(), String> { |
| 54 | let repo_path = self.git_data_path.join(&announcement.repo_path()); | 54 | let repo_path = self.git_data_path.join(announcement.repo_path()); |
| 55 | 55 | ||
| 56 | // Check if repository already exists | 56 | // Check if repository already exists |
| 57 | if repo_path.exists() { | 57 | if repo_path.exists() { |
| @@ -69,7 +69,7 @@ impl Nip34WritePolicy { | |||
| 69 | 69 | ||
| 70 | // Initialize bare repository using git command | 70 | // Initialize bare repository using git command |
| 71 | let output = std::process::Command::new("git") | 71 | let output = std::process::Command::new("git") |
| 72 | .args(&["init", "--bare", repo_path.to_str().unwrap()]) | 72 | .args(["init", "--bare", repo_path.to_str().unwrap()]) |
| 73 | .output() | 73 | .output() |
| 74 | .map_err(|e| format!("Failed to execute git init: {}", e))?; | 74 | .map_err(|e| format!("Failed to execute git init: {}", e))?; |
| 75 | 75 | ||
| @@ -482,7 +482,7 @@ impl Nip34WritePolicy { | |||
| 482 | }; | 482 | }; |
| 483 | 483 | ||
| 484 | // Build repository path | 484 | // Build repository path |
| 485 | let repo_path = self.git_data_path.join(&announcement.repo_path()); | 485 | let repo_path = self.git_data_path.join(announcement.repo_path()); |
| 486 | 486 | ||
| 487 | // Validate the ref | 487 | // Validate the ref |
| 488 | match git::validate_nostr_ref(&repo_path, &event_id, &expected_commit) { | 488 | match git::validate_nostr_ref(&repo_path, &event_id, &expected_commit) { |
| @@ -631,8 +631,8 @@ impl Nip34WritePolicy { | |||
| 631 | let kind_u16 = event.kind.as_u16(); | 631 | let kind_u16 = event.kind.as_u16(); |
| 632 | 632 | ||
| 633 | // Check if this is any kind of replaceable event | 633 | // Check if this is any kind of replaceable event |
| 634 | let is_regular_replaceable = kind_u16 >= 10000 && kind_u16 < 20000; | 634 | let is_regular_replaceable = (10000..20000).contains(&kind_u16); |
| 635 | let is_parameterized_replaceable = kind_u16 >= 30000 && kind_u16 < 40000; | 635 | let is_parameterized_replaceable = (30000..40000).contains(&kind_u16); |
| 636 | 636 | ||
| 637 | if is_regular_replaceable || is_parameterized_replaceable { | 637 | if is_regular_replaceable || is_parameterized_replaceable { |
| 638 | // Build the appropriate address format based on event type | 638 | // Build the appropriate address format based on event type |
| @@ -669,7 +669,7 @@ impl Nip34WritePolicy { | |||
| 669 | ]; | 669 | ]; |
| 670 | 670 | ||
| 671 | for tag_type in &addressable_tags { | 671 | for tag_type in &addressable_tags { |
| 672 | let filter = Filter::new().custom_tag(tag_type.clone(), address.clone()); | 672 | let filter = Filter::new().custom_tag(*tag_type, address.clone()); |
| 673 | 673 | ||
| 674 | match database.query(filter).await { | 674 | match database.query(filter).await { |
| 675 | Ok(events) => { | 675 | Ok(events) => { |
| @@ -691,7 +691,7 @@ impl Nip34WritePolicy { | |||
| 691 | ]; | 691 | ]; |
| 692 | 692 | ||
| 693 | for tag_type in &event_id_tags { | 693 | for tag_type in &event_id_tags { |
| 694 | let filter = Filter::new().custom_tag(tag_type.clone(), event_id_hex.clone()); | 694 | let filter = Filter::new().custom_tag(*tag_type, event_id_hex.clone()); |
| 695 | 695 | ||
| 696 | match database.query(filter).await { | 696 | match database.query(filter).await { |
| 697 | Ok(events) => { | 697 | Ok(events) => { |
diff --git a/src/nostr/events.rs b/src/nostr/events.rs index 6a62ccd..050bfdd 100644 --- a/src/nostr/events.rs +++ b/src/nostr/events.rs | |||
| @@ -322,9 +322,9 @@ impl RepositoryState { | |||
| 322 | 322 | ||
| 323 | /// Get the HEAD branch name (without refs/heads/ prefix) | 323 | /// Get the HEAD branch name (without refs/heads/ prefix) |
| 324 | pub fn get_head_branch(&self) -> Option<&str> { | 324 | pub fn get_head_branch(&self) -> Option<&str> { |
| 325 | self.head.as_ref().and_then(|h| { | 325 | self.head |
| 326 | h.strip_prefix("refs/heads/") | 326 | .as_ref() |
| 327 | }) | 327 | .and_then(|h| h.strip_prefix("refs/heads/")) |
| 328 | } | 328 | } |
| 329 | 329 | ||
| 330 | /// Check if the HEAD commit is available in the git repository | 330 | /// Check if the HEAD commit is available in the git repository |
| @@ -397,7 +397,7 @@ pub fn validate_state(event: &Event) -> Result<()> { | |||
| 397 | #[cfg(test)] | 397 | #[cfg(test)] |
| 398 | mod tests { | 398 | mod tests { |
| 399 | use super::*; | 399 | use super::*; |
| 400 | use nostr_sdk::{EventBuilder, Keys, Tag}; | 400 | use nostr_sdk::{EventBuilder, Keys}; |
| 401 | 401 | ||
| 402 | fn create_test_keys() -> Keys { | 402 | fn create_test_keys() -> Keys { |
| 403 | Keys::generate() | 403 | Keys::generate() |
| @@ -618,7 +618,10 @@ mod tests { | |||
| 618 | 618 | ||
| 619 | let announcement = RepositoryAnnouncement::from_event(event).unwrap(); | 619 | let announcement = RepositoryAnnouncement::from_event(event).unwrap(); |
| 620 | assert_eq!(announcement.maintainers.len(), 1); | 620 | assert_eq!(announcement.maintainers.len(), 1); |
| 621 | assert_eq!(announcement.maintainers[0], maintainer_keys.public_key().to_hex()); | 621 | assert_eq!( |
| 622 | announcement.maintainers[0], | ||
| 623 | maintainer_keys.public_key().to_hex() | ||
| 624 | ); | ||
| 622 | } | 625 | } |
| 623 | 626 | ||
| 624 | #[test] | 627 | #[test] |
| @@ -727,10 +730,7 @@ mod tests { | |||
| 727 | 730 | ||
| 728 | let keys = create_test_keys(); | 731 | let keys = create_test_keys(); |
| 729 | let tags = vec![ | 732 | let tags = vec![ |
| 730 | Tag::custom( | 733 | Tag::custom(nostr_sdk::TagKind::d(), vec!["test-repo".to_string()]), |
| 731 | nostr_sdk::TagKind::d(), | ||
| 732 | vec!["test-repo".to_string()], | ||
| 733 | ), | ||
| 734 | Tag::custom( | 734 | Tag::custom( |
| 735 | nostr_sdk::TagKind::Custom("refs/heads/main".into()), | 735 | nostr_sdk::TagKind::Custom("refs/heads/main".into()), |
| 736 | vec!["a1b2c3d4".to_string()], | 736 | vec!["a1b2c3d4".to_string()], |