diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-05-23 14:44:39 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-05-23 14:44:39 +0100 |
| commit | 3b4f0b0eee124133b641d6770704c368712f3dff (patch) | |
| tree | d13bddcb798d36bf95235a0408f8392e93dd8fff | |
| parent | 1083153ea340b57620870a47ce7653aeae3d1196 (diff) | |
feat: add NIP-31 alt tags
to repo announcements, patches and cover letters
| -rw-r--r-- | src/repo_ref.rs | 15 | ||||
| -rw-r--r-- | src/sub_commands/send.rs | 10 | ||||
| -rw-r--r-- | tests/init.rs | 17 | ||||
| -rw-r--r-- | tests/send.rs | 39 |
4 files changed, 79 insertions, 2 deletions
diff --git a/src/repo_ref.rs b/src/repo_ref.rs index 3e8db64..d314e6d 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs | |||
| @@ -136,6 +136,10 @@ impl RepoRef { | |||
| 136 | .map(std::string::ToString::to_string) | 136 | .map(std::string::ToString::to_string) |
| 137 | .collect(), | 137 | .collect(), |
| 138 | ), | 138 | ), |
| 139 | Tag::Generic( | ||
| 140 | nostr::TagKind::Custom("alt".to_string()), | ||
| 141 | vec![format!("git repository: {}", self.name.clone())], | ||
| 142 | ), | ||
| 139 | ], | 143 | ], |
| 140 | // code languages and hashtags | 144 | // code languages and hashtags |
| 141 | ] | 145 | ] |
| @@ -451,6 +455,15 @@ mod tests { | |||
| 451 | .any(|t| t.as_vec()[0].eq("name") && t.as_vec()[1].eq("test name")) | 455 | .any(|t| t.as_vec()[0].eq("name") && t.as_vec()[1].eq("test name")) |
| 452 | ) | 456 | ) |
| 453 | } | 457 | } |
| 458 | |||
| 459 | #[test] | ||
| 460 | fn alt() { | ||
| 461 | assert!( | ||
| 462 | create().tags.iter().any(|t| t.as_vec()[0].eq("alt") | ||
| 463 | && t.as_vec()[1].eq("git repository: test name")) | ||
| 464 | ) | ||
| 465 | } | ||
| 466 | |||
| 454 | #[test] | 467 | #[test] |
| 455 | fn description() { | 468 | fn description() { |
| 456 | assert!(create().tags.iter().any( | 469 | assert!(create().tags.iter().any( |
| @@ -515,7 +528,7 @@ mod tests { | |||
| 515 | 528 | ||
| 516 | #[test] | 529 | #[test] |
| 517 | fn no_other_tags() { | 530 | fn no_other_tags() { |
| 518 | assert_eq!(create().tags.len(), 8) | 531 | assert_eq!(create().tags.len(), 9) |
| 519 | } | 532 | } |
| 520 | } | 533 | } |
| 521 | } | 534 | } |
diff --git a/src/sub_commands/send.rs b/src/sub_commands/send.rs index 4639b01..189dc53 100644 --- a/src/sub_commands/send.rs +++ b/src/sub_commands/send.rs | |||
| @@ -649,6 +649,10 @@ pub fn generate_cover_letter_and_patch_events( | |||
| 649 | }, | 649 | }, |
| 650 | Tag::Reference(format!("{root_commit}")), | 650 | Tag::Reference(format!("{root_commit}")), |
| 651 | Tag::Hashtag("cover-letter".to_string()), | 651 | Tag::Hashtag("cover-letter".to_string()), |
| 652 | Tag::Generic( | ||
| 653 | nostr::TagKind::Custom("alt".to_string()), | ||
| 654 | vec![format!("git patch cover letter: {}", title.clone())], | ||
| 655 | ), | ||
| 652 | ], | 656 | ], |
| 653 | if let Some(event_ref) = root_proposal_id.clone() { | 657 | if let Some(event_ref) = root_proposal_id.clone() { |
| 654 | vec![ | 658 | vec![ |
| @@ -895,6 +899,7 @@ pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { | |||
| 895 | } | 899 | } |
| 896 | 900 | ||
| 897 | #[allow(clippy::too_many_arguments)] | 901 | #[allow(clippy::too_many_arguments)] |
| 902 | #[allow(clippy::too_many_lines)] | ||
| 898 | pub fn generate_patch_event( | 903 | pub fn generate_patch_event( |
| 899 | git_repo: &Repo, | 904 | git_repo: &Repo, |
| 900 | root_commit: &Sha1Hash, | 905 | root_commit: &Sha1Hash, |
| @@ -912,6 +917,7 @@ pub fn generate_patch_event( | |||
| 912 | .get_commit_parent(commit) | 917 | .get_commit_parent(commit) |
| 913 | .context("failed to get parent commit")?; | 918 | .context("failed to get parent commit")?; |
| 914 | let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); | 919 | let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); |
| 920 | |||
| 915 | EventBuilder::new( | 921 | EventBuilder::new( |
| 916 | nostr::event::Kind::Custom(PATCH_KIND), | 922 | nostr::event::Kind::Custom(PATCH_KIND), |
| 917 | git_repo | 923 | git_repo |
| @@ -937,6 +943,10 @@ pub fn generate_patch_event( | |||
| 937 | // code that makes it into the main branch, assuming | 943 | // code that makes it into the main branch, assuming |
| 938 | // the commit id is correct | 944 | // the commit id is correct |
| 939 | Tag::Reference(commit.to_string()), | 945 | Tag::Reference(commit.to_string()), |
| 946 | Tag::Generic( | ||
| 947 | nostr::TagKind::Custom("alt".to_string()), | ||
| 948 | vec![format!("git patch: {}", git_repo.get_commit_message_summary(commit).unwrap_or_default())], | ||
| 949 | ), | ||
| 940 | ], | 950 | ], |
| 941 | 951 | ||
| 942 | if let Some(thread_event_id) = thread_event_id { | 952 | if let Some(thread_event_id) = thread_event_id { |
diff --git a/tests/init.rs b/tests/init.rs index 2083c82..1beeaa5 100644 --- a/tests/init.rs +++ b/tests/init.rs | |||
| @@ -338,6 +338,23 @@ mod when_repo_not_previously_claimed { | |||
| 338 | 338 | ||
| 339 | #[tokio::test] | 339 | #[tokio::test] |
| 340 | #[serial] | 340 | #[serial] |
| 341 | async fn alt() -> Result<()> { | ||
| 342 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; | ||
| 343 | for relay in [&r53, &r55, &r56, &r57] { | ||
| 344 | let event: &nostr::Event = relay | ||
| 345 | .events | ||
| 346 | .iter() | ||
| 347 | .find(|e| e.kind.as_u64().eq(&REPOSITORY_KIND)) | ||
| 348 | .unwrap(); | ||
| 349 | |||
| 350 | assert!(event.tags.iter().any(|t| t.as_vec()[0].eq("alt") | ||
| 351 | && t.as_vec()[1].eq("git repository: example-name"))); | ||
| 352 | } | ||
| 353 | Ok(()) | ||
| 354 | } | ||
| 355 | |||
| 356 | #[tokio::test] | ||
| 357 | #[serial] | ||
| 341 | async fn description() -> Result<()> { | 358 | async fn description() -> Result<()> { |
| 342 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; | 359 | let (_, _, r53, r55, r56, r57) = prep_run_init().await?; |
| 343 | for relay in [&r53, &r55, &r56, &r57] { | 360 | for relay in [&r53, &r55, &r56, &r57] { |
diff --git a/tests/send.rs b/tests/send.rs index 8474c19..aa16949 100644 --- a/tests/send.rs +++ b/tests/send.rs | |||
| @@ -448,7 +448,7 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ | |||
| 448 | 448 | ||
| 449 | #[tokio::test] | 449 | #[tokio::test] |
| 450 | #[serial] | 450 | #[serial] |
| 451 | async fn pr_tags_branch_name() -> Result<()> { | 451 | async fn cover_letter_tags_branch_name() -> Result<()> { |
| 452 | let (_, _, r53, r55, r56) = prep_run_create_proposal(true).await?; | 452 | let (_, _, r53, r55, r56) = prep_run_create_proposal(true).await?; |
| 453 | for relay in [&r53, &r55, &r56] { | 453 | for relay in [&r53, &r55, &r56] { |
| 454 | let cover_letter_event: &nostr::Event = | 454 | let cover_letter_event: &nostr::Event = |
| @@ -466,6 +466,27 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ | |||
| 466 | } | 466 | } |
| 467 | Ok(()) | 467 | Ok(()) |
| 468 | } | 468 | } |
| 469 | |||
| 470 | #[tokio::test] | ||
| 471 | #[serial] | ||
| 472 | async fn cover_letter_tags_alt() -> Result<()> { | ||
| 473 | let (_, _, r53, r55, r56) = prep_run_create_proposal(true).await?; | ||
| 474 | for relay in [&r53, &r55, &r56] { | ||
| 475 | let cover_letter_event: &nostr::Event = | ||
| 476 | relay.events.iter().find(|e| is_cover_letter(e)).unwrap(); | ||
| 477 | |||
| 478 | // branch-name tag | ||
| 479 | assert_eq!( | ||
| 480 | cover_letter_event | ||
| 481 | .iter_tags() | ||
| 482 | .find(|t| t.as_vec()[0].eq("alt")) | ||
| 483 | .unwrap() | ||
| 484 | .as_vec()[1], | ||
| 485 | "git patch cover letter: exampletitle" | ||
| 486 | ); | ||
| 487 | } | ||
| 488 | Ok(()) | ||
| 489 | } | ||
| 469 | } | 490 | } |
| 470 | 491 | ||
| 471 | mod patch_tags { | 492 | mod patch_tags { |
| @@ -605,6 +626,22 @@ mod when_cover_letter_details_specified_with_range_of_head_2_sends_cover_letter_ | |||
| 605 | 626 | ||
| 606 | #[tokio::test] | 627 | #[tokio::test] |
| 607 | #[serial] | 628 | #[serial] |
| 629 | async fn alt() -> Result<()> { | ||
| 630 | assert_eq!( | ||
| 631 | prep() | ||
| 632 | .await? | ||
| 633 | .tags | ||
| 634 | .iter() | ||
| 635 | .find(|t| t.as_vec()[0].eq("alt")) | ||
| 636 | .unwrap() | ||
| 637 | .as_vec(), | ||
| 638 | vec!["alt", "git patch: add t3.md"], | ||
| 639 | ); | ||
| 640 | Ok(()) | ||
| 641 | } | ||
| 642 | |||
| 643 | #[tokio::test] | ||
| 644 | #[serial] | ||
| 608 | async fn patch_tags_cover_letter_event_as_root() -> Result<()> { | 645 | async fn patch_tags_cover_letter_event_as_root() -> Result<()> { |
| 609 | let (_, _, r53, r55, r56) = prep_run_create_proposal(true).await?; | 646 | let (_, _, r53, r55, r56) = prep_run_create_proposal(true).await?; |
| 610 | for relay in [&r53, &r55, &r56] { | 647 | for relay in [&r53, &r55, &r56] { |