upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-18 11:56:15 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-18 11:56:15 +0100
commit3eb2354edb8e76428625d5645e110c30aa1ccc2a (patch)
tree59798e071817e2a8b155b15230a367005181ac56 /src/bin/git_remote_nostr
parent757c2f888b2be2b37ea01e02a6c020c5f8c7aa9c (diff)
feat(pr): list PR and PR updates
remote will list the refs under `pr/*` namespace. `ngit list` will display in the list of open / draft proposals. it won't yet fetch the related oids to enable fetching or checking out the branch.
Diffstat (limited to 'src/bin/git_remote_nostr')
-rw-r--r--src/bin/git_remote_nostr/list.rs56
-rw-r--r--src/bin/git_remote_nostr/utils.rs25
2 files changed, 63 insertions, 18 deletions
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs
index b9fb0c0..7bdf170 100644
--- a/src/bin/git_remote_nostr/list.rs
+++ b/src/bin/git_remote_nostr/list.rs
@@ -11,7 +11,7 @@ use ngit::{
11 self, 11 self,
12 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, 12 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol},
13 }, 13 },
14 git_events::event_to_cover_letter, 14 git_events::{KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_to_cover_letter, tag_value},
15 login::get_curent_user, 15 login::get_curent_user,
16 repo_ref::{self, is_grasp_server}, 16 repo_ref::{self, is_grasp_server},
17}; 17};
@@ -122,6 +122,16 @@ async fn get_open_and_draft_proposals_state(
122 122
123 // without trusting commit_id we must apply each patch which requires the oid of 123 // without trusting commit_id we must apply each patch which requires the oid of
124 // the parent so we much do a fetch 124 // the parent so we much do a fetch
125
126 // As we are fetching from git servers we mighgt as well get oids from pull
127 // request too
128 // TODO get Pull Request and Pull Request Update Events add these to
129 // refs/nostr/<event-id>
130 // TODO prepare PRs and PRS oids to try and fetch from repo servers that are or
131 // clone urls in PR/update event we are using anyway. TODO after we tried
132 // and failed to get them from these server we should fallback to fetch them
133 // from listed clone urls in PR/update but not during list, only during fetch
134
125 for (git_server_url, (oids_from_git_servers, is_grasp_server)) in remote_states { 135 for (git_server_url, (oids_from_git_servers, is_grasp_server)) in remote_states {
126 if fetch_from_git_server( 136 if fetch_from_git_server(
127 git_repo, 137 git_repo,
@@ -144,7 +154,7 @@ async fn get_open_and_draft_proposals_state(
144 let mut state = HashMap::new(); 154 let mut state = HashMap::new();
145 let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?; 155 let open_and_draft_proposals = get_open_or_draft_proposals(git_repo, repo_ref).await?;
146 let current_user = get_curent_user(git_repo)?; 156 let current_user = get_curent_user(git_repo)?;
147 for (_, (proposal, patches)) in open_and_draft_proposals { 157 for (_, (proposal, events_to_apply)) in open_and_draft_proposals {
148 if let Ok(cl) = event_to_cover_letter(&proposal) { 158 if let Ok(cl) = event_to_cover_letter(&proposal) {
149 if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() { 159 if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() {
150 branch_name = if let Some(public_key) = current_user { 160 branch_name = if let Some(public_key) = current_user {
@@ -156,15 +166,43 @@ async fn get_open_and_draft_proposals_state(
156 } else { 166 } else {
157 branch_name 167 branch_name
158 }; 168 };
159 match make_commits_for_proposal(git_repo, repo_ref, &patches) { 169 // if events_to_apply contains a PR or PR Update event it should be the only
160 Ok(tip) => { 170 // event in the Vec
161 state.insert(format!("refs/heads/{branch_name}"), tip); 171 if let Some(pr_or_pr_update) = events_to_apply
172 .iter()
173 .find(|e| e.kind.eq(&KIND_PULL_REQUEST) || e.kind.eq(&KIND_PULL_REQUEST_UPDATE))
174 {
175 match tag_value(pr_or_pr_update, "c") {
176 Ok(tip) => {
177 state.insert(format!("refs/heads/{branch_name}"), tip);
178 }
179 Err(_) => {
180 let _ = term.write_line(
181 format!(
182 "WARNING: failed to fetch branch {branch_name} error: {} event poorly formatted",
183 if pr_or_pr_update.kind.eq(&KIND_PULL_REQUEST) {
184 "PR"
185 } else {
186 "PR update"
187 }
188 )
189 .as_str(),
190 );
191 }
162 } 192 }
163 Err(error) => { 193 } else {
164 let _ = term.write_line( 194 match make_commits_for_proposal(git_repo, repo_ref, &events_to_apply) {
165 format!("WARNING: failed to fetch branch {branch_name} error: {error}") 195 Ok(tip) => {
196 state.insert(format!("refs/heads/{branch_name}"), tip);
197 }
198 Err(error) => {
199 let _ = term.write_line(
200 format!(
201 "WARNING: failed to fetch branch {branch_name} error: {error}"
202 )
166 .as_str(), 203 .as_str(),
167 ); 204 );
205 }
168 } 206 }
169 } 207 }
170 } 208 }
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs
index dc75872..d0b4e7e 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,
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,
@@ -140,12 +140,15 @@ pub async fn get_open_or_draft_proposals(
140 Kind::GitStatusOpen 140 Kind::GitStatusOpen
141 }; 141 };
142 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) { 142 if [Kind::GitStatusOpen, Kind::GitStatusDraft].contains(&status) {
143 if let Ok(commits_events) = 143 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) 144 git_repo_path,
145 .await 145 repo_ref,
146 &proposal.id,
147 )
148 .await
146 { 149 {
147 if let Ok(most_recent_proposal_patch_chain) = 150 if let Ok(most_recent_proposal_patch_chain) =
148 get_most_recent_patch_with_ancestors(commits_events.clone()) 151 get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone())
149 { 152 {
150 open_or_draft_proposals 153 open_or_draft_proposals
151 .insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); 154 .insert(proposal.id, (proposal, most_recent_proposal_patch_chain));
@@ -172,11 +175,15 @@ pub async fn get_all_proposals(
172 let mut all_proposals = HashMap::new(); 175 let mut all_proposals = HashMap::new();
173 176
174 for proposal in proposals { 177 for proposal in proposals {
175 if let Ok(commits_events) = 178 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 179 git_repo_path,
180 repo_ref,
181 &proposal.id,
182 )
183 .await
177 { 184 {
178 if let Ok(most_recent_proposal_patch_chain) = 185 if let Ok(most_recent_proposal_patch_chain) =
179 get_most_recent_patch_with_ancestors(commits_events.clone()) 186 get_pr_tip_event_or_most_recent_patch_with_ancestors(commits_events.clone())
180 { 187 {
181 all_proposals.insert(proposal.id, (proposal, most_recent_proposal_patch_chain)); 188 all_proposals.insert(proposal.id, (proposal, most_recent_proposal_patch_chain));
182 } 189 }