upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-13 17:00:00 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-13 17:00:00 +0100
commit069a4c21c56291455fb9af09b693672889f98a03 (patch)
treeb4bc6de0114def18abca3380a0491c9ebe230245 /src/lib
parent39bd66ed80d8d0e32e7231f1881b789392f5dacc (diff)
refactor: abstract find pr from branch name
so it is done consistantly across ngit and the remote helper
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/git_events.rs18
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;
3use anyhow::{bail, Context, Result}; 3use anyhow::{bail, Context, Result};
4use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19}; 4use nostr::nips::{nip01::Coordinate, nip10::Marker, nip19::Nip19};
5use nostr_sdk::{ 5use 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};
9use nostr_signer::NostrSigner; 9use 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
597pub 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)]
598mod tests { 612mod tests {
599 use super::*; 613 use super::*;