upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/git_remote_nostr/list.rs4
-rw-r--r--test_utils/src/lib.rs20
-rw-r--r--tests/git_remote_nostr/list.rs2
3 files changed, 24 insertions, 2 deletions
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs
index 137c13f..f5eaee4 100644
--- a/src/bin/git_remote_nostr/list.rs
+++ b/src/bin/git_remote_nostr/list.rs
@@ -86,7 +86,7 @@ pub async fn run_list(
86 ); 86 );
87 87
88 state.extend( 88 state.extend(
89 // get as refs/pr/<branch-name>(<shorthand-event-id>) 89 // get as refs/pr/<branch-name>(<shorthand-event-id>) and refs/pr-by-id/<event-id>
90 get_all_proposals_state(git_repo, repo_ref).await?, 90 get_all_proposals_state(git_repo, repo_ref).await?,
91 ); 91 );
92 92
@@ -248,11 +248,13 @@ async fn get_all_proposals_state(
248 { 248 {
249 if let Ok(tip) = tag_value(pr_or_pr_update, "c") { 249 if let Ok(tip) = tag_value(pr_or_pr_update, "c") {
250 state.insert(format!("refs/{branch_name}"), tip.clone()); 250 state.insert(format!("refs/{branch_name}"), tip.clone());
251 state.insert(format!("refs/pr-by-id/{}", proposal.id), tip);
251 } 252 }
252 } else if let Ok(tip) = 253 } else if let Ok(tip) =
253 make_commits_for_proposal(git_repo, repo_ref, &events_to_apply) 254 make_commits_for_proposal(git_repo, repo_ref, &events_to_apply)
254 { 255 {
255 state.insert(format!("refs/{branch_name}"), tip.clone()); 256 state.insert(format!("refs/{branch_name}"), tip.clone());
257 state.insert(format!("refs/pr-by-id/{}", proposal.id), tip);
256 } 258 }
257 } 259 }
258 } 260 }
diff --git a/test_utils/src/lib.rs b/test_utils/src/lib.rs
index 3e348a4..8d81efe 100644
--- a/test_utils/src/lib.rs
+++ b/test_utils/src/lib.rs
@@ -12,7 +12,7 @@ use dialoguer::theme::{ColorfulTheme, Theme};
12use futures::{executor::block_on, future::join_all}; 12use futures::{executor::block_on, future::join_all};
13use git::GitTestRepo; 13use git::GitTestRepo;
14use git2::{Signature, Time}; 14use git2::{Signature, Time};
15use nostr::{self, Kind, Tag, nips::nip65::RelayMetadata}; 15use nostr::{self, Kind, Tag, event::EventId, nips::nip65::RelayMetadata};
16use nostr_database::NostrDatabase; 16use nostr_database::NostrDatabase;
17use nostr_lmdb::NostrLMDB; 17use nostr_lmdb::NostrLMDB;
18use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json}; 18use nostr_sdk::{Client, Event, NostrSigner, TagStandard, serde_json};
@@ -1197,6 +1197,24 @@ pub fn get_proposal_branch_name_from_events(
1197 bail!("failed to find proposal root with branch-name tag matching title") 1197 bail!("failed to find proposal root with branch-name tag matching title")
1198} 1198}
1199 1199
1200pub fn get_proposal_id_from_branch_name(
1201 events: &[nostr::Event],
1202 branch_name_in_event: &str,
1203) -> Result<EventId> {
1204 let mut events = events.to_owned();
1205 events.reverse();
1206 for event in events {
1207 if event
1208 .tags
1209 .iter()
1210 .any(|t| t.as_slice()[0].eq("branch-name") && t.as_slice()[1].eq(branch_name_in_event))
1211 {
1212 return Ok(event.id);
1213 }
1214 }
1215 bail!("failed to find proposal root with branch-name tag matching title")
1216}
1217
1200pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t"; 1218pub static FEATURE_BRANCH_NAME_1: &str = "feature-example-t";
1201pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f"; 1219pub static FEATURE_BRANCH_NAME_2: &str = "feature-example-f";
1202pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c"; 1220pub static FEATURE_BRANCH_NAME_3: &str = "feature-example-c";
diff --git a/tests/git_remote_nostr/list.rs b/tests/git_remote_nostr/list.rs
index a2dfe8c..50ea350 100644
--- a/tests/git_remote_nostr/list.rs
+++ b/tests/git_remote_nostr/list.rs
@@ -327,6 +327,8 @@ mod with_state_announcement {
327 let branch_name = get_proposal_branch_name_from_events(&r55.events, name)?; 327 let branch_name = get_proposal_branch_name_from_events(&r55.events, name)?;
328 pr_refs.push(format!("{tip} refs/heads/{branch_name}")); 328 pr_refs.push(format!("{tip} refs/heads/{branch_name}"));
329 pr_refs.push(format!("{tip} refs/{branch_name}")); 329 pr_refs.push(format!("{tip} refs/{branch_name}"));
330 let proposal_id = get_proposal_id_from_branch_name(&r55.events, name)?;
331 pr_refs.push(format!("{tip} refs/pr-by-id/{proposal_id}"));
330 } 332 }
331 333
332 assert_eq!( 334 assert_eq!(