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:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 16:12:27 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-25 16:12:27 +0100
commite89dbc142f5a0a517f197562f5f228681d9aed47 (patch)
tree521dbec8d259f7c982345b40bb128a21795a2012 /src/bin/git_remote_nostr/utils.rs
parent419b827f7c0d826f5eedf574bce0cf9b85cab4ca (diff)
parent0cad465dd3f78bd6c680067d12d396d4782829bf (diff)
Merge branch 'add-PR-feature-to-remote'
Diffstat (limited to 'src/bin/git_remote_nostr/utils.rs')
-rw-r--r--src/bin/git_remote_nostr/utils.rs59
1 files changed, 30 insertions, 29 deletions
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index dc75872..2cb85bf 100644
--- a/src/bin/git_remote_nostr/utils.rs
+++ b/src/bin/git_remote_nostr/utils.rs
@@ -10,7 +10,7 @@ use anyhow::{Context, Result, bail};
10use git2::Repository; 10use git2::Repository;
11use ngit::{ 11use ngit::{
12 client::{ 12 client::{
13 get_all_proposal_patch_events_from_cache, get_events_from_local_cache, 13 get_all_proposal_patch_pr_pr_update_events_from_cache, get_events_from_local_cache,
14 get_proposals_and_revisions_from_cache, 14 get_proposals_and_revisions_from_cache,
15 }, 15 },
16 git::{ 16 git::{
@@ -18,7 +18,7 @@ use ngit::{
18 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, 18 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol},
19 }, 19 },
20 git_events::{ 20 git_events::{
21 event_is_revision_root, get_most_recent_patch_with_ancestors, 21 event_is_revision_root, get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status,
22 is_event_proposal_root_for_branch, status_kinds, 22 is_event_proposal_root_for_branch, status_kinds,
23 }, 23 },
24 repo_ref::RepoRef, 24 repo_ref::RepoRef,
@@ -103,7 +103,10 @@ pub async fn get_open_or_draft_proposals(
103 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())
104 .await? 104 .await?
105 .iter() 105 .iter()
106 .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))
107 .cloned() 110 .cloned()
108 .collect(); 111 .collect();
109 112
@@ -123,32 +126,23 @@ pub async fn get_open_or_draft_proposals(
123 }; 126 };
124 let mut open_or_draft_proposals = HashMap::new(); 127 let mut open_or_draft_proposals = HashMap::new();
125 128
126 for proposal in proposals { 129 for proposal in &proposals {
127 let status = if let Some(e) = statuses 130 let status = get_status(proposal, repo_ref, &statuses, &proposals);
128 .iter()
129 .filter(|e| {
130 status_kinds().contains(&e.kind)
131 && e.tags.iter().any(|t| {
132 t.as_slice().len() > 1 && t.as_slice()[1].eq(&proposal.id.to_string())
133 })
134 })
135 .collect::<Vec<&nostr::Event>>()
136 .first()
137 {
138 e.kind
139 } else {
140 Kind::GitStatusOpen
141 };
142 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) { 131 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) {
143 if let Ok(commits_events) = 132 if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache(
144 get_all_proposal_patch_events_from_cache(git_repo_path, repo_ref, &proposal.id) 133 git_repo_path,
145 .await 134 repo_ref,
135 &proposal.id,
136 )
137 .await
146 { 138 {
147 if let Ok(most_recent_proposal_patch_chain) = 139 if let Ok(most_recent_proposal_patch_chain) =
148 get_most_recent_patch_with_ancestors(commits_events.clone()) 140 get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone())
149 { 141 {
150 open_or_draft_proposals 142 open_or_draft_proposals.insert(
151 .insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); 143 proposal.id,
144 (proposal.clone(), most_recent_proposal_patch_chain),
145 );
152 } 146 }
153 } 147 }
154 } 148 }
@@ -165,18 +159,25 @@ pub async fn get_all_proposals(
165 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())
166 .await? 160 .await?
167 .iter() 161 .iter()
168 .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))
169 .cloned() 166 .cloned()
170 .collect(); 167 .collect();
171 168
172 let mut all_proposals = HashMap::new(); 169 let mut all_proposals = HashMap::new();
173 170
174 for proposal in proposals { 171 for proposal in proposals {
175 if let Ok(commits_events) = 172 if let Ok(commits_events) = get_all_proposal_patch_pr_pr_update_events_from_cache(
176 get_all_proposal_patch_events_from_cache(git_repo_path, repo_ref, &proposal.id).await 173 git_repo_path,
174 repo_ref,
175 &proposal.id,
176 )
177 .await
177 { 178 {
178 if let Ok(most_recent_proposal_patch_chain) = 179 if let Ok(most_recent_proposal_patch_chain) =
179 get_most_recent_patch_with_ancestors(commits_events.clone()) 180 get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone())
180 { 181 {
181 all_proposals.insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); 182 all_proposals.insert(proposal.id, (proposal, most_recent_proposal_patch_chain));
182 } 183 }