upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git_events.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 11:48:22 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 16:10:57 +0100
commit9357b62b9824299be6fc85b09f57d93d3902f79a (patch)
tree04de089315d58bc6b4c5fc4df786d9604a1abb61 /src/lib/git_events.rs
parent802b115ca648011fd311a22ef3650aaa5a1a0acf (diff)
refactor: abstract `get_status`
for use by `ngit list`
Diffstat (limited to 'src/lib/git_events.rs')
-rw-r--r--src/lib/git_events.rs56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs
index 7cd64ab..2e1f215 100644
--- a/src/lib/git_events.rs
+++ b/src/lib/git_events.rs
@@ -835,7 +835,61 @@ pub fn is_event_proposal_root_for_branch(
835 || cl 835 || cl
836 .get_branch_name_with_pr_prefix_and_shorthand_id() 836 .get_branch_name_with_pr_prefix_and_shorthand_id()
837 .is_ok_and(|s| s.eq(&branch_name)) 837 .is_ok_and(|s| s.eq(&branch_name))
838 }) && !event_is_revision_root(e)) 838 }) && (
839 // If we wanted to treat to list Pull Requests that revise a Patch we would do this:
840 // Note: whilst this the the case elsewhere event_is_revision_root is used, there is more to
841 // think about here?
842 // e.kind.eq(&KIND_PULL_REQUEST) ||
843 !event_is_revision_root(e)
844 ))
845}
846
847pub fn get_status(
848 proposal: &Event,
849 repo_ref: &RepoRef,
850 all_status_in_repo: &[Event],
851 all_pr_roots_in_repo: &[Event],
852) -> Kind {
853 let get_direct_status = |proposal: &Event| {
854 if let Some(e) = all_status_in_repo
855 .iter()
856 .filter(|e| {
857 status_kinds().contains(&e.kind)
858 && e.tags.iter().any(|t| {
859 t.as_slice().len() > 1 && t.as_slice()[1].eq(&proposal.id.to_string())
860 })
861 && (proposal.pubkey.eq(&e.pubkey) || repo_ref.maintainers.contains(&e.pubkey))
862 })
863 .collect::<Vec<&nostr::Event>>()
864 .first()
865 {
866 e.kind
867 } else {
868 Kind::GitStatusOpen
869 }
870 };
871 let is_proposal_pr_revision_of_patch = |proposal: &Event, patch: &Event| {
872 proposal.kind.eq(&KIND_PULL_REQUEST)
873 && proposal.tags.clone().into_iter().any(|t| {
874 t.as_slice().len() > 1
875 && t.as_slice()[0].eq("e")
876 && t.as_slice()[1].eq(&patch.id.to_string())
877 })
878 };
879
880 let direct_status = get_direct_status(proposal);
881 if direct_status.eq(&Kind::GitStatusClosed) && proposal.kind.eq(&Kind::GitPatch) {
882 if let Some(pr_revision) = all_pr_roots_in_repo
883 .iter()
884 .find(|p| is_proposal_pr_revision_of_patch(p, proposal))
885 {
886 get_direct_status(pr_revision)
887 } else {
888 direct_status
889 }
890 } else {
891 direct_status
892 }
839} 893}
840 894
841#[cfg(test)] 895#[cfg(test)]