upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/git_remote_nostr/utils.rs')
-rw-r--r--src/bin/git_remote_nostr/utils.rs58
1 files changed, 12 insertions, 46 deletions
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index 8433967..2cb85bf 100644
--- a/src/bin/git_remote_nostr/utils.rs
+++ b/src/bin/git_remote_nostr/utils.rs
@@ -18,9 +18,8 @@ use ngit::{
18 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, 18 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol},
19 }, 19 },
20 git_events::{ 20 git_events::{
21 KIND_PULL_REQUEST, event_is_revision_root, 21 event_is_revision_root, get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status,
22 get_pr_tip_event_or_most_recent_patch_with_ancestors, is_event_proposal_root_for_branch, 22 is_event_proposal_root_for_branch, status_kinds,
23 status_kinds,
24 }, 23 },
25 repo_ref::RepoRef, 24 repo_ref::RepoRef,
26}; 25};
@@ -104,7 +103,10 @@ pub async fn get_open_or_draft_proposals(
104 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) 103 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates())
105 .await? 104 .await?
106 .iter() 105 .iter()
107 .filter(|e| !event_is_revision_root(e)) 106 .filter(|e|
107 // If we wanted to treat to list Pull Requests that revise a Patch we would do this:
108 // e.kind.eq(&KIND_PULL_REQUEST) ||
109 !event_is_revision_root(e))
108 .cloned() 110 .cloned()
109 .collect(); 111 .collect();
110 112
@@ -124,48 +126,9 @@ pub async fn get_open_or_draft_proposals(
124 }; 126 };
125 let mut open_or_draft_proposals = HashMap::new(); 127 let mut open_or_draft_proposals = HashMap::new();
126 128
127 let get_status = |proposal: &Event| {
128 if let Some(e) = statuses
129 .iter()
130 .filter(|e| {
131 status_kinds().contains(&e.kind)
132 && e.tags.iter().any(|t| {
133 t.as_slice().len() > 1 && t.as_slice()[1].eq(&proposal.id.to_string())
134 })
135 && (proposal.pubkey.eq(&e.pubkey) || repo_ref.maintainers.contains(&e.pubkey))
136 })
137 .collect::<Vec<&nostr::Event>>()
138 .first()
139 {
140 e.kind
141 } else {
142 Kind::GitStatusOpen
143 }
144 };
145
146 let is_proposal_pr_revision_of_patch = |proposal: &Event, patch: &Event| {
147 proposal.kind.eq(&KIND_PULL_REQUEST)
148 && proposal.tags.clone().into_iter().any(|t| {
149 t.as_slice().len() > 1
150 && t.as_slice()[0].eq("e")
151 && t.as_slice()[1].eq(&patch.id.to_string())
152 && [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&get_status(proposal))
153 })
154 };
155
156 for proposal in &proposals { 129 for proposal in &proposals {
157 let status = get_status(proposal); 130 let status = get_status(proposal, repo_ref, &statuses, &proposals);
158 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) 131 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) {
159 || // or patch has been revised as a PR which is open or draft
160 (
161 status.eq(&Kind::GitStatusClosed) &&
162 proposal.kind.eq(&Kind::GitPatch) &&
163 proposals.iter()
164 .any(|p| {
165 is_proposal_pr_revision_of_patch(p, proposal)
166 })
167 )
168 {
169 if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache( 132 if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache(
170 git_repo_path, 133 git_repo_path,
171 repo_ref, 134 repo_ref,
@@ -196,7 +159,10 @@ pub async fn get_all_proposals(
196 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) 159 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates())
197 .await? 160 .await?
198 .iter() 161 .iter()
199 .filter(|e| !event_is_revision_root(e)) 162 .filter(|e|
163 // If we wanted to treat to list Pull Requests that revise a Patch we would do this:
164 // e.kind.eq(&KIND_PULL_REQUEST) ||
165 !event_is_revision_root(e))
200 .cloned() 166 .cloned()
201 .collect(); 167 .collect();
202 168