diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/git_events.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index b4ac676..d818f4c 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -3,8 +3,8 @@ use std::str::FromStr; | |||
| 3 | use anyhow::{bail, Context, Result}; | 3 | use anyhow::{bail, Context, Result}; |
| 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; | 4 | use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; |
| 5 | use nostr_sdk::{ | 5 | use nostr_sdk::{ |
| 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, Tag, TagKind, | 6 | hashes::sha1::Hash as Sha1Hash, Event, EventBuilder, EventId, FromBech32, Kind, PublicKey, Tag, |
| 7 | TagStandard, UncheckedUrl, | 7 | TagKind, TagStandard, UncheckedUrl, |
| 8 | }; | 8 | }; |
| 9 | use nostr_signer::NostrSigner; | 9 | use nostr_signer::NostrSigner; |
| 10 | 10 | ||
| @@ -594,6 +594,20 @@ fn get_event_parent_id(event: &nostr::Event) -> Result<String> { | |||
| 594 | .clone()) | 594 | .clone()) |
| 595 | } | 595 | } |
| 596 | 596 | ||
| 597 | pub fn is_event_proposal_root_for_branch( | ||
| 598 | e: &Event, | ||
| 599 | branch_name_or_refstr: &str, | ||
| 600 | logged_in_user: &Option<PublicKey>, | ||
| 601 | ) -> Result<bool> { | ||
| 602 | let branch_name = branch_name_or_refstr.replace("refs/heads/", ""); | ||
| 603 | Ok(event_to_cover_letter(e).is_ok_and(|cl| { | ||
| 604 | (logged_in_user.is_some_and(|public_key| e.author().eq(&public_key)) | ||
| 605 | && (branch_name.eq(&format!("pr/{}", cl.branch_name)) | ||
| 606 | || cl.branch_name.eq(&branch_name))) | ||
| 607 | || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)) | ||
| 608 | }) && !event_is_revision_root(e)) | ||
| 609 | } | ||
| 610 | |||
| 597 | #[cfg(test)] | 611 | #[cfg(test)] |
| 598 | mod tests { | 612 | mod tests { |
| 599 | use super::*; | 613 | use super::*; |