From 8638b321fdff94d034ec912ecd0910b6f564ff04 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 24 Jul 2024 16:37:10 +0100 Subject: refactor: use nip34 kinds from rust-nostr instead of Kind::Custom(u16) as v33 of rust-nostr introduced them --- src/client.rs | 26 ++++++++---------- src/repo_ref.rs | 16 +++++------ src/sub_commands/init.rs | 4 +-- src/sub_commands/list.rs | 69 ++++++++++++++++++++++-------------------------- src/sub_commands/send.rs | 30 ++++++++++----------- test_utils/src/git.rs | 4 +-- test_utils/src/lib.rs | 7 ++--- tests/init.rs | 30 +++++++++++---------- tests/list.rs | 2 +- tests/send.rs | 19 +++++++------ 10 files changed, 99 insertions(+), 108 deletions(-) diff --git a/src/client.rs b/src/client.rs index 29d390f..5603014 100644 --- a/src/client.rs +++ b/src/client.rs @@ -36,10 +36,10 @@ use nostr_sqlite::SQLiteDatabase; use crate::{ config::get_dirs, login::{get_logged_in_user, get_user_ref_from_cache}, - repo_ref::{RepoRef, REPO_REF_KIND}, + repo_ref::RepoRef, sub_commands::{ list::status_kinds, - send::{event_is_patch_set_root, event_is_revision_root, PATCH_KIND}, + send::{event_is_patch_set_root, event_is_revision_root}, }, }; @@ -212,7 +212,7 @@ impl Connect for Client { }); } save_event_in_cache(git_repo_path, &event).await?; - if event.kind().eq(&Kind::Custom(REPO_REF_KIND)) { + if event.kind().eq(&Kind::GitRepoAnnouncement) { save_event_in_global_cache(git_repo_path, &event).await?; } Ok(event.id()) @@ -895,7 +895,7 @@ async fn create_relays_request( git_repo_path, vec![ nostr::Filter::default() - .kinds(vec![Kind::Custom(PATCH_KIND)]) + .kinds(vec![Kind::GitPatch]) .custom_tag( SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), repo_coordinates_without_relays @@ -1070,7 +1070,7 @@ async fn process_fetched_events( for event in &events { if !request.existing_events.contains(&event.id) { save_event_in_cache(git_repo_path, event).await?; - if event.kind().as_u16().eq(&REPO_REF_KIND) { + if event.kind().eq(&Kind::GitRepoAnnouncement) { save_event_in_global_cache(git_repo_path, event).await?; let new_coordinate = !request .repo_coordinates_without_relays @@ -1172,7 +1172,7 @@ async fn process_fetched_events( if !request.existing_events.contains(&event.id) && !event.event_ids().any(|id| report.proposals.contains(id)) { - if event.kind().as_u16() == PATCH_KIND && !event_is_patch_set_root(event) { + if event.kind().eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { report.commits.insert(event.id); } else if status_kinds().contains(&event.kind()) { report.statuses.insert(event.id); @@ -1238,7 +1238,7 @@ pub fn get_fetch_filters( vec![ get_filter_repo_events(repo_coordinates), nostr::Filter::default() - .kinds(vec![Kind::Custom(PATCH_KIND), Kind::EventDeletion]) + .kinds(vec![Kind::GitPatch, Kind::EventDeletion]) .custom_tag( SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), repo_coordinates @@ -1252,13 +1252,9 @@ pub fn get_fetch_filters( vec![] } else { vec![ - nostr::Filter::default().events(proposal_ids.clone()).kinds( - [ - vec![Kind::Custom(PATCH_KIND), Kind::EventDeletion], - status_kinds(), - ] - .concat(), - ), + nostr::Filter::default() + .events(proposal_ids.clone()) + .kinds([vec![Kind::GitPatch, Kind::EventDeletion], status_kinds()].concat()), ] }, if required_profiles.is_empty() { @@ -1272,7 +1268,7 @@ pub fn get_fetch_filters( pub fn get_filter_repo_events(repo_coordinates: &HashSet) -> nostr::Filter { nostr::Filter::default() - .kind(Kind::Custom(REPO_REF_KIND)) + .kind(Kind::GitRepoAnnouncement) .identifiers( repo_coordinates .iter() diff --git a/src/repo_ref.rs b/src/repo_ref.rs index 0409502..ca196d9 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs @@ -37,7 +37,7 @@ impl TryFrom for RepoRef { type Error = anyhow::Error; fn try_from(event: nostr::Event) -> Result { - if !event.kind.as_u16().eq(&REPO_REF_KIND) { + if !event.kind.eq(&Kind::GitRepoAnnouncement) { bail!("incorrect kind"); } let mut r = Self::default(); @@ -107,13 +107,11 @@ impl TryFrom for RepoRef { } } -pub static REPO_REF_KIND: u16 = 30_617; - impl RepoRef { pub async fn to_event(&self, signer: &NostrSigner) -> Result { sign_event( nostr_sdk::EventBuilder::new( - nostr::event::Kind::Custom(REPO_REF_KIND), + nostr::event::Kind::GitRepoAnnouncement, "", [ vec![ @@ -179,7 +177,7 @@ impl RepoRef { let mut res = HashSet::new(); for m in &self.maintainers { res.insert(Coordinate { - kind: Kind::Custom(REPO_REF_KIND), + kind: Kind::GitRepoAnnouncement, public_key: *m, identifier: self.identifier.clone(), relays: vec![], @@ -191,7 +189,7 @@ impl RepoRef { /// coordinates without relay hints pub fn coordinate_with_hint(&self) -> Coordinate { Coordinate { - kind: Kind::Custom(REPO_REF_KIND), + kind: Kind::GitRepoAnnouncement, public_key: *self .maintainers .first() @@ -256,7 +254,7 @@ pub async fn try_and_get_repo_coordinates( if let Some(identifier) = repo_config.identifier { for public_key in maintainers { repo_coordinates.insert(Coordinate { - kind: Kind::Custom(REPO_REF_KIND), + kind: Kind::GitRepoAnnouncement, public_key, identifier: identifier.clone(), relays: vec![], @@ -283,7 +281,7 @@ pub async fn try_and_get_repo_coordinates( } // look find all repo refs with root_commit. for identifier let filter = nostr::Filter::default() - .kind(nostr::Kind::Custom(REPO_REF_KIND)) + .kind(nostr::Kind::GitRepoAnnouncement) .reference(git_repo.get_root_commit()?.to_string()) .authors(maintainers.clone()); let mut events = @@ -306,7 +304,7 @@ pub async fn try_and_get_repo_coordinates( for m in &repo_config.maintainers { if let Ok(maintainer) = PublicKey::parse(m) { repo_coordinates.insert(Coordinate { - kind: Kind::Custom(REPO_REF_KIND), + kind: Kind::GitRepoAnnouncement, public_key: maintainer, identifier: identifier.to_string(), relays: vec![], diff --git a/src/sub_commands/init.rs b/src/sub_commands/init.rs index 2a97779..1c51375 100644 --- a/src/sub_commands/init.rs +++ b/src/sub_commands/init.rs @@ -16,7 +16,7 @@ use crate::{ login, repo_ref::{ extract_pks, get_repo_config_from_yaml, save_repo_config_to_yaml, - try_and_get_repo_coordinates, RepoRef, REPO_REF_KIND, + try_and_get_repo_coordinates, RepoRef, }, Cli, }; @@ -336,7 +336,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { git_repo.save_git_config_item( "nostr.repo", &Coordinate { - kind: Kind::Custom(REPO_REF_KIND), + kind: Kind::GitRepoAnnouncement, public_key: user_ref.public_key, identifier: identifier.clone(), relays: vec![], diff --git a/src/sub_commands/list.rs b/src/sub_commands/list.rs index cc7ac6f..73ef107 100644 --- a/src/sub_commands/list.rs +++ b/src/sub_commands/list.rs @@ -2,7 +2,7 @@ use std::{collections::HashSet, io::Write, ops::Add, path::Path}; use anyhow::{bail, Context, Result}; use nostr::nips::nip01::Coordinate; -use nostr_sdk::PublicKey; +use nostr_sdk::{Kind, PublicKey}; use super::send::event_is_patch_set_root; #[cfg(test)] @@ -16,7 +16,7 @@ use crate::{ repo_ref::{get_repo_coordinates, RepoRef}, sub_commands::send::{ commit_msg_from_patch_oneliner, event_is_cover_letter, event_is_revision_root, - event_to_cover_letter, patch_supports_commit_ids, PATCH_KIND, + event_to_cover_letter, patch_supports_commit_ids, }, }; @@ -84,31 +84,31 @@ pub async fn launch() -> Result<()> { .collect::>() .first() { - e.kind().as_u16() + e.kind() } else { - STATUS_KIND_OPEN + Kind::GitStatusOpen }; - if status.eq(&STATUS_KIND_OPEN) { + if status.eq(&Kind::GitStatusOpen) { open_proposals.push(proposal); - } else if status.eq(&STATUS_KIND_CLOSED) { + } else if status.eq(&Kind::GitStatusClosed) { closed_proposals.push(proposal); - } else if status.eq(&STATUS_KIND_DRAFT) { + } else if status.eq(&Kind::GitStatusDraft) { draft_proposals.push(proposal); - } else if status.eq(&STATUS_KIND_APPLIED) { + } else if status.eq(&Kind::GitStatusApplied) { applied_proposals.push(proposal); } } - let mut selected_status = STATUS_KIND_OPEN; + let mut selected_status = Kind::GitStatusOpen; loop { - let proposals_for_status = if selected_status == STATUS_KIND_OPEN { + let proposals_for_status = if selected_status == Kind::GitStatusOpen { &open_proposals - } else if selected_status == STATUS_KIND_DRAFT { + } else if selected_status == Kind::GitStatusDraft { &draft_proposals - } else if selected_status == STATUS_KIND_CLOSED { + } else if selected_status == Kind::GitStatusClosed { &closed_proposals - } else if selected_status == STATUS_KIND_APPLIED { + } else if selected_status == Kind::GitStatusApplied { &applied_proposals } else { &open_proposals @@ -116,15 +116,15 @@ pub async fn launch() -> Result<()> { let prompt = if proposals.len().eq(&open_proposals.len()) { "all proposals" - } else if selected_status == STATUS_KIND_OPEN { + } else if selected_status == Kind::GitStatusOpen { if open_proposals.is_empty() { "proposals menu" } else { "open proposals" } - } else if selected_status == STATUS_KIND_DRAFT { + } else if selected_status == Kind::GitStatusDraft { "draft proposals" - } else if selected_status == STATUS_KIND_CLOSED { + } else if selected_status == Kind::GitStatusClosed { "closed proposals" } else { "applied proposals" @@ -143,16 +143,16 @@ pub async fn launch() -> Result<()> { }) .collect(); - if !selected_status.eq(&STATUS_KIND_OPEN) && open_proposals.len().gt(&0) { + if !selected_status.eq(&Kind::GitStatusOpen) && open_proposals.len().gt(&0) { choices.push(format!("({}) Open proposals...", open_proposals.len())); } - if !selected_status.eq(&STATUS_KIND_DRAFT) && draft_proposals.len().gt(&0) { + if !selected_status.eq(&Kind::GitStatusDraft) && draft_proposals.len().gt(&0) { choices.push(format!("({}) Draft proposals...", draft_proposals.len())); } - if !selected_status.eq(&STATUS_KIND_CLOSED) && closed_proposals.len().gt(&0) { + if !selected_status.eq(&Kind::GitStatusClosed) && closed_proposals.len().gt(&0) { choices.push(format!("({}) Closed proposals...", closed_proposals.len())); } - if !selected_status.eq(&STATUS_KIND_APPLIED) && applied_proposals.len().gt(&0) { + if !selected_status.eq(&Kind::GitStatusApplied) && applied_proposals.len().gt(&0) { choices.push(format!( "({}) Applied proposals...", applied_proposals.len() @@ -167,13 +167,13 @@ pub async fn launch() -> Result<()> { if (selected_index + 1).gt(&proposals_for_status.len()) { if choices[selected_index].contains("Open") { - selected_status = STATUS_KIND_OPEN; + selected_status = Kind::GitStatusOpen; } else if choices[selected_index].contains("Draft") { - selected_status = STATUS_KIND_DRAFT; + selected_status = Kind::GitStatusDraft; } else if choices[selected_index].contains("Closed") { - selected_status = STATUS_KIND_CLOSED; + selected_status = Kind::GitStatusClosed; } else if choices[selected_index].contains("Applied") { - selected_status = STATUS_KIND_APPLIED; + selected_status = Kind::GitStatusApplied; } continue; } @@ -804,17 +804,12 @@ pub fn get_most_recent_patch_with_ancestors( Ok(res) } -pub static STATUS_KIND_OPEN: u16 = 1630; -pub static STATUS_KIND_APPLIED: u16 = 1631; -pub static STATUS_KIND_CLOSED: u16 = 1632; -pub static STATUS_KIND_DRAFT: u16 = 1633; - pub fn status_kinds() -> Vec { vec![ - nostr::Kind::Custom(STATUS_KIND_OPEN), - nostr::Kind::Custom(STATUS_KIND_APPLIED), - nostr::Kind::Custom(STATUS_KIND_CLOSED), - nostr::Kind::Custom(STATUS_KIND_DRAFT), + nostr::Kind::GitStatusOpen, + nostr::Kind::GitStatusApplied, + nostr::Kind::GitStatusClosed, + nostr::Kind::GitStatusDraft, ] } @@ -826,7 +821,7 @@ pub async fn get_proposals_and_revisions_from_cache( git_repo_path, vec![ nostr::Filter::default() - .kind(nostr::Kind::Custom(PATCH_KIND)) + .kind(nostr::Kind::GitPatch) .custom_tag( nostr::SingleLetterTag::lowercase(nostr_sdk::Alphabet::A), repo_coordinates @@ -855,10 +850,10 @@ pub async fn get_all_proposal_patch_events_from_cache( git_repo_path, vec![ nostr::Filter::default() - .kind(nostr::Kind::Custom(PATCH_KIND)) + .kind(nostr::Kind::GitPatch) .event(*proposal_id), nostr::Filter::default() - .kind(nostr::Kind::Custom(PATCH_KIND)) + .kind(nostr::Kind::GitPatch) .id(*proposal_id), ], ) @@ -891,7 +886,7 @@ pub async fn get_all_proposal_patch_events_from_cache( git_repo_path, vec![ nostr::Filter::default() - .kind(nostr::Kind::Custom(PATCH_KIND)) + .kind(nostr::Kind::GitPatch) .events(revision_roots) .authors(permissioned_users.clone()), ], diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 9733cfe..73c980b 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs @@ -12,7 +12,7 @@ use nostr::{ }, EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, }; -use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, NostrSigner, TagStandard}; +use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, Kind, NostrSigner, TagStandard}; use super::list::tag_value; #[cfg(not(test))] @@ -28,7 +28,7 @@ use crate::{ }, git::{Repo, RepoActions}, login, - repo_ref::{get_repo_coordinates, RepoRef, REPO_REF_KIND}, + repo_ref::{get_repo_coordinates, RepoRef}, Cli, }; @@ -288,7 +288,10 @@ pub async fn send_events( ) -> Result<()> { let fallback = [ client.get_fallback_relays().clone(), - if events.iter().any(|e| e.kind().as_u16().eq(&REPO_REF_KIND)) { + if events + .iter() + .any(|e| e.kind().eq(&Kind::GitRepoAnnouncement)) + { client.get_blaster_relays().clone() } else { vec![] @@ -573,8 +576,6 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( Ok((root_proposal_id, mention_tags)) } -pub static PATCH_KIND: u16 = 1617; - #[allow(clippy::too_many_lines)] pub async fn generate_cover_letter_and_patch_events( cover_letter_title_description: Option<(String, String)>, @@ -593,7 +594,7 @@ pub async fn generate_cover_letter_and_patch_events( if let Some((title, description)) = cover_letter_title_description { events.push(sign_event(EventBuilder::new( - nostr::event::Kind::Custom(PATCH_KIND), + nostr::event::Kind::GitPatch, format!( "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", commits.last().unwrap(), @@ -601,7 +602,7 @@ pub async fn generate_cover_letter_and_patch_events( ), [ repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { - kind: nostr::Kind::Custom(REPO_REF_KIND), + kind: nostr::Kind::GitRepoAnnouncement, public_key: *m, identifier: repo_ref.identifier.to_string(), relays: repo_ref.relays.clone(), @@ -789,7 +790,7 @@ pub fn event_is_cover_letter(event: &nostr::Event) -> bool { // TODO: look for Subject:[ PATCH 0/n ] but watch out for: // [PATCH v1 0/n ] or // [PATCH subsystem v2 0/n ] - event.kind.as_u16().eq(&PATCH_KIND) + event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) } @@ -860,16 +861,15 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result { } pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { - event.kind.as_u16().eq(&PATCH_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) + event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) } pub fn event_is_revision_root(event: &nostr::Event) -> bool { - event.kind.as_u16().eq(&PATCH_KIND) - && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) + event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) } pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { - event.kind.as_u16().eq(&PATCH_KIND) + event.kind.eq(&Kind::GitPatch) && event .iter_tags() .any(|t| t.as_vec()[0].eq("commit-pgp-sig")) @@ -897,7 +897,7 @@ pub async fn generate_patch_event( sign_event( EventBuilder::new( - nostr::event::Kind::Custom(PATCH_KIND), + nostr::event::Kind::GitPatch, git_repo .make_patch_from_commit(commit, &series_count) .context(format!("cannot make patch for commit {commit}"))?, @@ -907,7 +907,7 @@ pub async fn generate_patch_event( .iter() .map(|m| { Tag::coordinate(Coordinate { - kind: nostr::Kind::Custom(REPO_REF_KIND), + kind: nostr::Kind::GitRepoAnnouncement, public_key: *m, identifier: repo_ref.identifier.to_string(), relays: repo_ref.relays.clone(), @@ -1238,7 +1238,7 @@ mod tests { fn generate_cover_letter(title: &str, description: &str) -> Result { Ok(nostr::event::EventBuilder::new( - nostr::event::Kind::Custom(PATCH_KIND), + nostr::event::Kind::GitPatch, format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), [ Tag::hashtag("cover-letter"), diff --git a/test_utils/src/git.rs b/test_utils/src/git.rs index 7aa7e84..5e8aed5 100644 --- a/test_utils/src/git.rs +++ b/test_utils/src/git.rs @@ -8,7 +8,7 @@ use git2::{Oid, RepositoryInitOptions, Signature, Time}; use nostr::nips::nip01::Coordinate; use nostr_sdk::{Kind, ToBech32}; -use crate::{generate_repo_ref_event, REPOSITORY_KIND}; +use crate::generate_repo_ref_event; pub struct GitTestRepo { pub dir: PathBuf, @@ -19,7 +19,7 @@ impl Default for GitTestRepo { fn default() -> Self { let repo_event = generate_repo_ref_event(); let coordinate = Coordinate { - kind: Kind::Custom(REPOSITORY_KIND), + kind: Kind::GitRepoAnnouncement, public_key: repo_event.author(), identifier: repo_event.identifier().unwrap().to_string(), relays: vec![ diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs index 5125d20..bccfaf5 100644 --- a/test_utils/src/lib.rs +++ b/test_utils/src/lib.rs @@ -21,9 +21,6 @@ use tokio::runtime::Handle; pub mod git; pub mod relay; -pub static PATCH_KIND: u16 = 1617; -pub static REPOSITORY_KIND: u16 = 30617; - pub static TEST_KEY_1_NSEC: &str = "nsec1ppsg5sm2aexq06juxmu9evtutr6jkwkhp98exxxvwamhru9lyx9s3rwseq"; pub static TEST_KEY_1_SK_HEX: &str = @@ -158,7 +155,7 @@ pub fn generate_repo_ref_event() -> nostr::Event { // author and committer from global git config let root_commit = "9ee507fc4357d7ee16a5d8901bedcd103f23c17d"; nostr::event::EventBuilder::new( - nostr::Kind::Custom(REPOSITORY_KIND), + nostr::Kind::GitRepoAnnouncement, "", [ Tag::identifier( @@ -1244,7 +1241,7 @@ fn get_first_proposal_event_id() -> Result { let proposals = Handle::current().block_on(client.get_events_of( vec![ nostr::Filter::default() - .kind(nostr::Kind::Custom(PATCH_KIND)) + .kind(nostr::Kind::GitPatch) .custom_tag( nostr::SingleLetterTag::lowercase(nostr::Alphabet::T), vec!["root"], diff --git a/tests/init.rs b/tests/init.rs index 7e2e080..afd3848 100644 --- a/tests/init.rs +++ b/tests/init.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use nostr_sdk::Kind; use serial_test::serial; use test_utils::{git::GitTestRepo, *}; @@ -124,6 +125,7 @@ mod when_repo_not_previously_claimed { } mod sent_to_correct_relays { + use super::*; #[tokio::test] @@ -135,7 +137,7 @@ mod when_repo_not_previously_claimed { relay .events .iter() - .filter(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .filter(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .count(), 1, ); @@ -152,7 +154,7 @@ mod when_repo_not_previously_claimed { relay .events .iter() - .filter(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .filter(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .count(), 1, ); @@ -169,7 +171,7 @@ mod when_repo_not_previously_claimed { relay .events .iter() - .filter(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .filter(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .count(), 1, ); @@ -184,7 +186,7 @@ mod when_repo_not_previously_claimed { assert_eq!( r57.events .iter() - .filter(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .filter(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .count(), 1, ); @@ -324,7 +326,7 @@ mod when_repo_not_previously_claimed { .value() .unwrap(), Coordinate { - kind: nostr_sdk::Kind::Custom(REPOSITORY_KIND), + kind: nostr_sdk::Kind::GitRepoAnnouncement, identifier: "example-identifier".to_string(), public_key: TEST_KEY_1_KEYS.public_key(), relays: vec![], @@ -367,7 +369,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!( @@ -387,7 +389,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!(event.tags.iter().any(|t| t.as_vec()[0].eq("r") @@ -405,7 +407,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!( @@ -426,7 +428,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!(event.tags.iter().any(|t| t.as_vec()[0].eq("alt") @@ -443,7 +445,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!(event.tags.iter().any(|t| t.as_vec()[0].eq("description") @@ -460,7 +462,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); assert!( @@ -479,7 +481,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); let relays_tag = event .tags @@ -501,7 +503,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); let web_tag = event .tags @@ -523,7 +525,7 @@ mod when_repo_not_previously_claimed { let event: &nostr::Event = relay .events .iter() - .find(|e| e.kind.as_u16().eq(&REPOSITORY_KIND)) + .find(|e| e.kind.eq(&Kind::GitRepoAnnouncement)) .unwrap(); let maintainers_tag = event .tags diff --git a/tests/list.rs b/tests/list.rs index 6e509ac..ce90ee4 100644 --- a/tests/list.rs +++ b/tests/list.rs @@ -88,7 +88,7 @@ mod cannot_find_repo_event { let mut input = p.expect_input("repository naddr")?; input.succeeds_with( &Coordinate { - kind: nostr::Kind::Custom(REPOSITORY_KIND), + kind: nostr::Kind::GitRepoAnnouncement, public_key: TEST_KEY_1_KEYS.public_key(), identifier: repo_event.identifier().unwrap().to_string(), relays: vec!["ws://localhost:8056".to_string()], diff --git a/tests/send.rs b/tests/send.rs index 0f18bd1..57987e3 100644 --- a/tests/send.rs +++ b/tests/send.rs @@ -1,5 +1,6 @@ use anyhow::Result; use futures::join; +use nostr_sdk::Kind; use serial_test::serial; use test_utils::{git::GitTestRepo, relay::Relay, *}; @@ -84,13 +85,11 @@ mod when_commits_behind_ask_to_proceed { } fn is_cover_letter(event: &nostr::Event) -> bool { - event.kind.as_u16().eq(&PATCH_KIND) - && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) + event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) } fn is_patch(event: &nostr::Event) -> bool { - event.kind.as_u16().eq(&PATCH_KIND) - && !event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) + event.kind.eq(&Kind::GitPatch) && !event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) } fn prep_git_repo() -> Result { @@ -386,12 +385,14 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ relay.events.iter().find(|e| is_cover_letter(e)).unwrap(); assert!(cover_letter_event.iter_tags().any(|t| t.as_vec()[0].eq("a") && t.as_vec()[1].eq(&format!( - "{REPOSITORY_KIND}:{TEST_KEY_1_PUBKEY_HEX}:{}", + "{}:{TEST_KEY_1_PUBKEY_HEX}:{}", + Kind::GitRepoAnnouncement, generate_repo_ref_event().identifier().unwrap() )))); assert!(cover_letter_event.iter_tags().any(|t| t.as_vec()[0].eq("a") && t.as_vec()[1].eq(&format!( - "{REPOSITORY_KIND}:{TEST_KEY_2_PUBKEY_HEX}:{}", + "{}:{TEST_KEY_2_PUBKEY_HEX}:{}", + Kind::GitRepoAnnouncement, generate_repo_ref_event().identifier().unwrap() )))); } @@ -577,14 +578,16 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ assert!(prep().await?.tags.iter().any(|t| { t.as_vec()[0].eq("a") && t.as_vec()[1].eq(&format!( - "{REPOSITORY_KIND}:{TEST_KEY_1_PUBKEY_HEX}:{}", + "{}:{TEST_KEY_1_PUBKEY_HEX}:{}", + Kind::GitRepoAnnouncement, generate_repo_ref_event().identifier().unwrap() )) })); assert!(prep().await?.tags.iter().any(|t| { t.as_vec()[0].eq("a") && t.as_vec()[1].eq(&format!( - "{REPOSITORY_KIND}:{TEST_KEY_2_PUBKEY_HEX}:{}", + "{}:{TEST_KEY_2_PUBKEY_HEX}:{}", + Kind::GitRepoAnnouncement, generate_repo_ref_event().identifier().unwrap() )) })); -- cgit v1.2.3