diff options
Diffstat (limited to 'src/sub_commands/send.rs')
| -rw-r--r-- | src/sub_commands/send.rs | 30 |
1 files changed, 15 insertions, 15 deletions
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::{ | |||
| 12 | }, | 12 | }, |
| 13 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, | 13 | EventBuilder, FromBech32, Tag, TagKind, ToBech32, UncheckedUrl, |
| 14 | }; | 14 | }; |
| 15 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, NostrSigner, TagStandard}; | 15 | use nostr_sdk::{hashes::sha1::Hash as Sha1Hash, Kind, NostrSigner, TagStandard}; |
| 16 | 16 | ||
| 17 | use super::list::tag_value; | 17 | use super::list::tag_value; |
| 18 | #[cfg(not(test))] | 18 | #[cfg(not(test))] |
| @@ -28,7 +28,7 @@ use crate::{ | |||
| 28 | }, | 28 | }, |
| 29 | git::{Repo, RepoActions}, | 29 | git::{Repo, RepoActions}, |
| 30 | login, | 30 | login, |
| 31 | repo_ref::{get_repo_coordinates, RepoRef, REPO_REF_KIND}, | 31 | repo_ref::{get_repo_coordinates, RepoRef}, |
| 32 | Cli, | 32 | Cli, |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| @@ -288,7 +288,10 @@ pub async fn send_events( | |||
| 288 | ) -> Result<()> { | 288 | ) -> Result<()> { |
| 289 | let fallback = [ | 289 | let fallback = [ |
| 290 | client.get_fallback_relays().clone(), | 290 | client.get_fallback_relays().clone(), |
| 291 | if events.iter().any(|e| e.kind().as_u16().eq(&REPO_REF_KIND)) { | 291 | if events |
| 292 | .iter() | ||
| 293 | .any(|e| e.kind().eq(&Kind::GitRepoAnnouncement)) | ||
| 294 | { | ||
| 292 | client.get_blaster_relays().clone() | 295 | client.get_blaster_relays().clone() |
| 293 | } else { | 296 | } else { |
| 294 | vec![] | 297 | vec![] |
| @@ -573,8 +576,6 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to( | |||
| 573 | Ok((root_proposal_id, mention_tags)) | 576 | Ok((root_proposal_id, mention_tags)) |
| 574 | } | 577 | } |
| 575 | 578 | ||
| 576 | pub static PATCH_KIND: u16 = 1617; | ||
| 577 | |||
| 578 | #[allow(clippy::too_many_lines)] | 579 | #[allow(clippy::too_many_lines)] |
| 579 | pub async fn generate_cover_letter_and_patch_events( | 580 | pub async fn generate_cover_letter_and_patch_events( |
| 580 | cover_letter_title_description: Option<(String, String)>, | 581 | cover_letter_title_description: Option<(String, String)>, |
| @@ -593,7 +594,7 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 593 | 594 | ||
| 594 | if let Some((title, description)) = cover_letter_title_description { | 595 | if let Some((title, description)) = cover_letter_title_description { |
| 595 | events.push(sign_event(EventBuilder::new( | 596 | events.push(sign_event(EventBuilder::new( |
| 596 | nostr::event::Kind::Custom(PATCH_KIND), | 597 | nostr::event::Kind::GitPatch, |
| 597 | format!( | 598 | format!( |
| 598 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", | 599 | "From {} Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/{}] {title}\n\n{description}", |
| 599 | commits.last().unwrap(), | 600 | commits.last().unwrap(), |
| @@ -601,7 +602,7 @@ pub async fn generate_cover_letter_and_patch_events( | |||
| 601 | ), | 602 | ), |
| 602 | [ | 603 | [ |
| 603 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { | 604 | repo_ref.maintainers.iter().map(|m| Tag::coordinate(Coordinate { |
| 604 | kind: nostr::Kind::Custom(REPO_REF_KIND), | 605 | kind: nostr::Kind::GitRepoAnnouncement, |
| 605 | public_key: *m, | 606 | public_key: *m, |
| 606 | identifier: repo_ref.identifier.to_string(), | 607 | identifier: repo_ref.identifier.to_string(), |
| 607 | relays: repo_ref.relays.clone(), | 608 | relays: repo_ref.relays.clone(), |
| @@ -789,7 +790,7 @@ pub fn event_is_cover_letter(event: &nostr::Event) -> bool { | |||
| 789 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: | 790 | // TODO: look for Subject:[ PATCH 0/n ] but watch out for: |
| 790 | // [PATCH v1 0/n ] or | 791 | // [PATCH v1 0/n ] or |
| 791 | // [PATCH subsystem v2 0/n ] | 792 | // [PATCH subsystem v2 0/n ] |
| 792 | event.kind.as_u16().eq(&PATCH_KIND) | 793 | event.kind.eq(&Kind::GitPatch) |
| 793 | && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) | 794 | && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) |
| 794 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) | 795 | && event.iter_tags().any(|t| t.as_vec()[1].eq("cover-letter")) |
| 795 | } | 796 | } |
| @@ -860,16 +861,15 @@ pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { | |||
| 860 | } | 861 | } |
| 861 | 862 | ||
| 862 | pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { | 863 | pub fn event_is_patch_set_root(event: &nostr::Event) -> bool { |
| 863 | event.kind.as_u16().eq(&PATCH_KIND) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) | 864 | event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("root")) |
| 864 | } | 865 | } |
| 865 | 866 | ||
| 866 | pub fn event_is_revision_root(event: &nostr::Event) -> bool { | 867 | pub fn event_is_revision_root(event: &nostr::Event) -> bool { |
| 867 | event.kind.as_u16().eq(&PATCH_KIND) | 868 | event.kind.eq(&Kind::GitPatch) && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) |
| 868 | && event.iter_tags().any(|t| t.as_vec()[1].eq("revision-root")) | ||
| 869 | } | 869 | } |
| 870 | 870 | ||
| 871 | pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { | 871 | pub fn patch_supports_commit_ids(event: &nostr::Event) -> bool { |
| 872 | event.kind.as_u16().eq(&PATCH_KIND) | 872 | event.kind.eq(&Kind::GitPatch) |
| 873 | && event | 873 | && event |
| 874 | .iter_tags() | 874 | .iter_tags() |
| 875 | .any(|t| t.as_vec()[0].eq("commit-pgp-sig")) | 875 | .any(|t| t.as_vec()[0].eq("commit-pgp-sig")) |
| @@ -897,7 +897,7 @@ pub async fn generate_patch_event( | |||
| 897 | 897 | ||
| 898 | sign_event( | 898 | sign_event( |
| 899 | EventBuilder::new( | 899 | EventBuilder::new( |
| 900 | nostr::event::Kind::Custom(PATCH_KIND), | 900 | nostr::event::Kind::GitPatch, |
| 901 | git_repo | 901 | git_repo |
| 902 | .make_patch_from_commit(commit, &series_count) | 902 | .make_patch_from_commit(commit, &series_count) |
| 903 | .context(format!("cannot make patch for commit {commit}"))?, | 903 | .context(format!("cannot make patch for commit {commit}"))?, |
| @@ -907,7 +907,7 @@ pub async fn generate_patch_event( | |||
| 907 | .iter() | 907 | .iter() |
| 908 | .map(|m| { | 908 | .map(|m| { |
| 909 | Tag::coordinate(Coordinate { | 909 | Tag::coordinate(Coordinate { |
| 910 | kind: nostr::Kind::Custom(REPO_REF_KIND), | 910 | kind: nostr::Kind::GitRepoAnnouncement, |
| 911 | public_key: *m, | 911 | public_key: *m, |
| 912 | identifier: repo_ref.identifier.to_string(), | 912 | identifier: repo_ref.identifier.to_string(), |
| 913 | relays: repo_ref.relays.clone(), | 913 | relays: repo_ref.relays.clone(), |
| @@ -1238,7 +1238,7 @@ mod tests { | |||
| 1238 | 1238 | ||
| 1239 | fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> { | 1239 | fn generate_cover_letter(title: &str, description: &str) -> Result<nostr::Event> { |
| 1240 | Ok(nostr::event::EventBuilder::new( | 1240 | Ok(nostr::event::EventBuilder::new( |
| 1241 | nostr::event::Kind::Custom(PATCH_KIND), | 1241 | nostr::event::Kind::GitPatch, |
| 1242 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), | 1242 | format!("From ea897e987ea9a7a98e7a987e97987ea98e7a3334 Mon Sep 17 00:00:00 2001\nSubject: [PATCH 0/2] {title}\n\n{description}"), |
| 1243 | [ | 1243 | [ |
| 1244 | Tag::hashtag("cover-letter"), | 1244 | Tag::hashtag("cover-letter"), |