From 3b4f0b0eee124133b641d6770704c368712f3dff Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 23 May 2024 14:44:39 +0100 Subject: feat: add NIP-31 alt tags to repo announcements, patches and cover letters --- src/repo_ref.rs | 15 ++++++++++++++- src/sub_commands/send.rs | 10 ++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src') 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 { .map(std::string::ToString::to_string) .collect(), ), + Tag::Generic( + nostr::TagKind::Custom("alt".to_string()), + vec![format!("git repository: {}", self.name.clone())], + ), ], // code languages and hashtags ] @@ -451,6 +455,15 @@ mod tests { .any(|t| t.as_vec()[0].eq("name") && t.as_vec()[1].eq("test name")) ) } + + #[test] + fn alt() { + assert!( + create().tags.iter().any(|t| t.as_vec()[0].eq("alt") + && t.as_vec()[1].eq("git repository: test name")) + ) + } + #[test] fn description() { assert!(create().tags.iter().any( @@ -515,7 +528,7 @@ mod tests { #[test] fn no_other_tags() { - assert_eq!(create().tags.len(), 8) + assert_eq!(create().tags.len(), 9) } } } 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( }, Tag::Reference(format!("{root_commit}")), Tag::Hashtag("cover-letter".to_string()), + Tag::Generic( + nostr::TagKind::Custom("alt".to_string()), + vec![format!("git patch cover letter: {}", title.clone())], + ), ], if let Some(event_ref) = root_proposal_id.clone() { vec![ @@ -895,6 +899,7 @@ pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { } #[allow(clippy::too_many_arguments)] +#[allow(clippy::too_many_lines)] pub fn generate_patch_event( git_repo: &Repo, root_commit: &Sha1Hash, @@ -912,6 +917,7 @@ pub fn generate_patch_event( .get_commit_parent(commit) .context("failed to get parent commit")?; let relay_hint = repo_ref.relays.first().map(nostr::UncheckedUrl::from); + EventBuilder::new( nostr::event::Kind::Custom(PATCH_KIND), git_repo @@ -937,6 +943,10 @@ pub fn generate_patch_event( // code that makes it into the main branch, assuming // the commit id is correct Tag::Reference(commit.to_string()), + Tag::Generic( + nostr::TagKind::Custom("alt".to_string()), + vec![format!("git patch: {}", git_repo.get_commit_message_summary(commit).unwrap_or_default())], + ), ], if let Some(thread_event_id) = thread_event_id { -- cgit v1.2.3