From 6672f54dc166d7447e5c799f1809ecbb3d9ec04c Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 1 Nov 2023 00:00:00 +0000 Subject: feat(prs-create) use r instead of t tag for refs r tags are indexed by relays in they same way as t tags and are a more appropriate for referencing commits --- src/sub_commands/prs/create.rs | 15 +++++++++------ tests/prs_create.rs | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index e85611f..655978e 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs @@ -298,6 +298,9 @@ mod tests_unique_and_duplicate { } } +pub static PR_KIND: u64 = 318; +pub static PATCH_KIND: u64 = 317; + fn generate_pr_and_patch_events( title: &String, description: &String, @@ -311,9 +314,9 @@ fn generate_pr_and_patch_events( .context("failed to get root commit of the repository")?; let pr_event = EventBuilder::new( - nostr::event::Kind::Custom(318), + nostr::event::Kind::Custom(PR_KIND), format!("{title}\r\n\r\n{description}"), - &[Tag::Hashtag(format!("r-{root_commit}"))], + &[Tag::Reference(format!("r-{root_commit}"))], // TODO: suggested branch name // Tag::Generic( // TagKind::Custom("suggested-branch-name".to_string()), @@ -335,14 +338,14 @@ fn generate_pr_and_patch_events( .context("failed to create patch event")?; events.push( EventBuilder::new( - nostr::event::Kind::Custom(317), + nostr::event::Kind::Custom(PATCH_KIND), git_repo .make_patch_from_commit(commit) .context(format!("cannot make patch for commit {commit}"))?, &[ - Tag::Hashtag(format!("r-{root_commit}")), - Tag::Hashtag(commit.to_string()), - Tag::Hashtag(commit_parent.to_string()), + Tag::Reference(format!("r-{root_commit}")), + Tag::Reference(commit.to_string()), + Tag::Reference(commit_parent.to_string()), Tag::Event( pr_event_id, None, // TODO: add relay diff --git a/tests/prs_create.rs b/tests/prs_create.rs index 3b8aa31..72a85c8 100644 --- a/tests/prs_create.rs +++ b/tests/prs_create.rs @@ -420,8 +420,8 @@ mod sends_pr_and_2_patches_to_3_relays { .find(|e| e.kind.as_u64().eq(&PR_KIND)) .unwrap(); - // root commit 't' tag - assert!(pr_event.tags.iter().any(|t| t.as_vec()[0].eq("t") + // root commit 'r' tag + assert!(pr_event.tags.iter().any(|t| t.as_vec()[0].eq("r") && t.as_vec()[1].eq("r-9ee507fc4357d7ee16a5d8901bedcd103f23c17d"))); } Ok(()) @@ -444,12 +444,12 @@ mod sends_pr_and_2_patches_to_3_relays { static COMMIT_ID: &str = "fe973a840fba2a8ab37dd505c154854a69a6505c"; let most_recent_patch = patch_events[0]; - // commit 't' and 'commit' tag + // commit 'r' and 'commit' tag assert!( most_recent_patch .tags .iter() - .any(|t| t.as_vec()[0].eq("t") && t.as_vec()[1].eq(COMMIT_ID)) + .any(|t| t.as_vec()[0].eq("r") && t.as_vec()[1].eq(COMMIT_ID)) ); assert!( most_recent_patch @@ -464,14 +464,14 @@ mod sends_pr_and_2_patches_to_3_relays { most_recent_patch .tags .iter() - .any(|t| t.as_vec()[0].eq("t") && t.as_vec()[1].eq(COMMIT_PARENT_ID)) + .any(|t| t.as_vec()[0].eq("r") && t.as_vec()[1].eq(COMMIT_PARENT_ID)) ); assert!(most_recent_patch.tags.iter().any( |t| t.as_vec()[0].eq("parent-commit") && t.as_vec()[1].eq(COMMIT_PARENT_ID) )); // root commit 't' tag - assert!(most_recent_patch.tags.iter().any(|t| t.as_vec()[0].eq("t") + assert!(most_recent_patch.tags.iter().any(|t| t.as_vec()[0].eq("r") && t.as_vec()[1].eq("r-9ee507fc4357d7ee16a5d8901bedcd103f23c17d"))); } Ok(()) -- cgit v1.2.3