upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr/list.rs
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/list.rs
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/list.rs')
-rw-r--r--src/bin/git_remote_nostr/list.rs56
1 files changed, 47 insertions, 9 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 }