upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-07-31 16:28:04 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-07-31 16:38:45 +0100
commit436ff29135e3deade80a6e53e53d74dddb613481 (patch)
tree53c086492fd710f9f289c756ec511f8b3d3819f3
parent9d4adb9afd591ccef8827902034378acd700c6f8 (diff)
fix: mention marker ~> q tag NIP-10 update
required for rust-nostr v0.43 update
-rw-r--r--src/bin/git_remote_nostr/push.rs4
-rw-r--r--src/bin/ngit/sub_commands/send.rs23
-rw-r--r--src/lib/git_events.rs38
-rw-r--r--tests/git_remote_nostr/push.rs16
-rw-r--r--tests/ngit_send.rs3
5 files changed, 56 insertions, 28 deletions
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index 73d76b4..9ba7c30 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -1209,12 +1209,10 @@ async fn create_merge_status(
1209 merged_patches 1209 merged_patches
1210 .iter() 1210 .iter()
1211 .map(|merged_patch| { 1211 .map(|merged_patch| {
1212 Tag::from_standardized(nostr::TagStandard::Event { 1212 Tag::from_standardized(nostr::TagStandard::Quote {
1213 event_id: *merged_patch, 1213 event_id: *merged_patch,
1214 relay_url: repo_ref.relays.first().cloned(), 1214 relay_url: repo_ref.relays.first().cloned(),
1215 marker: Some(Marker::Mention),
1216 public_key: None, 1215 public_key: None,
1217 uppercase: false,
1218 }) 1216 })
1219 }) 1217 })
1220 .collect::<Vec<Tag>>(), 1218 .collect::<Vec<Tag>>(),
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs
index c84e339..8b49e37 100644
--- a/src/bin/ngit/sub_commands/send.rs
+++ b/src/bin/ngit/sub_commands/send.rs
@@ -4,12 +4,9 @@ use anyhow::{Context, Result, bail};
4use console::Style; 4use console::Style;
5use ngit::{ 5use ngit::{
6 client::{Params, send_events}, 6 client::{Params, send_events},
7 git_events::generate_cover_letter_and_patch_events, 7 git_events::{EventRefType, generate_cover_letter_and_patch_events},
8};
9use nostr::{
10 ToBech32,
11 nips::{nip10::Marker, nip19::Nip19Event},
12}; 8};
9use nostr::{ToBech32, nips::nip19::Nip19Event};
13use nostr_sdk::hashes::sha1::Hash as Sha1Hash; 10use nostr_sdk::hashes::sha1::Hash as Sha1Hash;
14 11
15use crate::{ 12use crate::{
@@ -368,7 +365,7 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to(
368 in_reply_to: &[String], 365 in_reply_to: &[String],
369) -> Result<(Option<String>, Vec<nostr::Tag>)> { 366) -> Result<(Option<String>, Vec<nostr::Tag>)> {
370 let root_proposal_id = if let Some(first) = in_reply_to.first() { 367 let root_proposal_id = if let Some(first) = in_reply_to.first() {
371 match event_tag_from_nip19_or_hex(first, "in-reply-to", Marker::Root, true, false)? 368 match event_tag_from_nip19_or_hex(first, "in-reply-to", EventRefType::Root, true, false)?
372 .as_standardized() 369 .as_standardized()
373 { 370 {
374 Some(nostr_sdk::TagStandard::Event { 371 Some(nostr_sdk::TagStandard::Event {
@@ -404,10 +401,16 @@ async fn get_root_proposal_id_and_mentions_from_in_reply_to(
404 for (i, reply_to) in in_reply_to.iter().enumerate() { 401 for (i, reply_to) in in_reply_to.iter().enumerate() {
405 if i.ne(&0) || root_proposal_id.is_none() { 402 if i.ne(&0) || root_proposal_id.is_none() {
406 mention_tags.push( 403 mention_tags.push(
407 event_tag_from_nip19_or_hex(reply_to, "in-reply-to", Marker::Mention, true, false) 404 event_tag_from_nip19_or_hex(
408 .context(format!( 405 reply_to,
409 "{reply_to} in 'in-reply-to' not a valid nostr reference" 406 "in-reply-to",
410 ))?, 407 EventRefType::Quote,
408 true,
409 false,
410 )
411 .context(format!(
412 "{reply_to} in 'in-reply-to' not a valid nostr reference"
413 ))?,
411 ); 414 );
412 } 415 }
413 } 416 }
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs
index 2e1f215..79f5772 100644
--- a/src/lib/git_events.rs
+++ b/src/lib/git_events.rs
@@ -184,7 +184,7 @@ pub async fn generate_patch_event(
184 event_tag_from_nip19_or_hex( 184 event_tag_from_nip19_or_hex(
185 &event_ref, 185 &event_ref,
186 "proposal", 186 "proposal",
187 Marker::Reply, 187 EventRefType::Reply,
188 false, 188 false,
189 false, 189 false,
190 )?, 190 )?,
@@ -277,10 +277,17 @@ pub async fn generate_patch_event(
277 .context("failed to sign event") 277 .context("failed to sign event")
278} 278}
279 279
280#[derive(Debug, PartialEq)]
281pub enum EventRefType {
282 Root,
283 Reply,
284 Quote,
285}
286
280pub fn event_tag_from_nip19_or_hex( 287pub fn event_tag_from_nip19_or_hex(
281 reference: &str, 288 reference: &str,
282 reference_name: &str, 289 reference_name: &str,
283 marker: Marker, 290 ref_type: EventRefType,
284 allow_npub_reference: bool, 291 allow_npub_reference: bool,
285 prompt_for_correction: bool, 292 prompt_for_correction: bool,
286) -> Result<nostr::Tag> { 293) -> Result<nostr::Tag> {
@@ -291,22 +298,41 @@ pub fn event_tag_from_nip19_or_hex(
291 PromptInputParms::default().with_prompt(format!("{reference_name} reference")), 298 PromptInputParms::default().with_prompt(format!("{reference_name} reference")),
292 )?; 299 )?;
293 } 300 }
301 let marker = match ref_type {
302 EventRefType::Root => Some(Marker::Root),
303 EventRefType::Reply => Some(Marker::Reply),
304 EventRefType::Quote => None,
305 };
294 if let Ok(nip19) = Nip19::from_bech32(&bech32) { 306 if let Ok(nip19) = Nip19::from_bech32(&bech32) {
295 match nip19 { 307 match nip19 {
296 Nip19::Event(n) => { 308 Nip19::Event(n) => {
309 if ref_type == EventRefType::Quote {
310 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Quote {
311 event_id: n.event_id,
312 relay_url: n.relays.first().cloned(),
313 public_key: None,
314 }));
315 }
297 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { 316 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event {
298 event_id: n.event_id, 317 event_id: n.event_id,
299 relay_url: n.relays.first().cloned(), 318 relay_url: n.relays.first().cloned(),
300 marker: Some(marker), 319 marker,
301 public_key: None, 320 public_key: None,
302 uppercase: false, 321 uppercase: false,
303 })); 322 }));
304 } 323 }
305 Nip19::EventId(id) => { 324 Nip19::EventId(id) => {
325 if ref_type == EventRefType::Quote {
326 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Quote {
327 event_id: id,
328 relay_url: None,
329 public_key: None,
330 }));
331 }
306 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { 332 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event {
307 event_id: id, 333 event_id: id,
308 relay_url: None, 334 relay_url: None,
309 marker: Some(marker), 335 marker,
310 public_key: None, 336 public_key: None,
311 uppercase: false, 337 uppercase: false,
312 })); 338 }));
@@ -335,7 +361,7 @@ pub fn event_tag_from_nip19_or_hex(
335 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event { 361 break Ok(Tag::from_standardized(nostr_sdk::TagStandard::Event {
336 event_id: id, 362 event_id: id,
337 relay_url: None, 363 relay_url: None,
338 marker: Some(marker), 364 marker,
339 public_key: None, 365 public_key: None,
340 uppercase: false, 366 uppercase: false,
341 })); 367 }));
@@ -574,7 +600,7 @@ pub async fn generate_cover_letter_and_patch_events(
574 Tag::hashtag("root"), 600 Tag::hashtag("root"),
575 Tag::hashtag("revision-root"), 601 Tag::hashtag("revision-root"),
576 // TODO check if id is for a root proposal (perhaps its for an issue?) 602 // TODO check if id is for a root proposal (perhaps its for an issue?)
577 event_tag_from_nip19_or_hex(&event_ref,"proposal",Marker::Reply, false, false)?, 603 event_tag_from_nip19_or_hex(&event_ref,"proposal",EventRefType::Reply, false, false)?,
578 ] 604 ]
579 } else { 605 } else {
580 vec![ 606 vec![
diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs
index 5912543..a137da5 100644
--- a/tests/git_remote_nostr/push.rs
+++ b/tests/git_remote_nostr/push.rs
@@ -1070,7 +1070,7 @@ async fn proposal_three_way_merge_commit_pushed_to_main_leads_to_status_event_is
1070 merge_status 1070 merge_status
1071 .tags 1071 .tags
1072 .iter() 1072 .iter()
1073 .find(|t| t.as_slice().len().eq(&4) && t.as_slice()[3].eq("mention")) 1073 .find(|t| t.as_slice()[0].eq("q"))
1074 .unwrap() 1074 .unwrap()
1075 .as_slice()[1], 1075 .as_slice()[1],
1076 "status mentions proposal tip event \r\nmerge status:\r\n{}\r\nproposal tip:\r\n{}", 1076 "status mentions proposal tip event \r\nmerge status:\r\n{}\r\nproposal tip:\r\n{}",
@@ -1252,9 +1252,10 @@ async fn proposal_fast_forward_merge_commits_pushed_to_main_leads_to_status_even
1252 .collect::<Vec<String>>() 1252 .collect::<Vec<String>>()
1253 { 1253 {
1254 assert!( 1254 assert!(
1255 merge_status.tags.iter().any(|t| t.as_slice().len().eq(&4) 1255 merge_status
1256 && t.as_slice()[1] == patch_id 1256 .tags
1257 && t.as_slice()[3].eq("mention")), 1257 .iter()
1258 .any(|t| t.as_slice()[0].eq("q") && t.as_slice()[1] == patch_id),
1258 "merge status doesnt mention proposal patch {patch_id} \r\nmerge status:\r\n{}", 1259 "merge status doesnt mention proposal patch {patch_id} \r\nmerge status:\r\n{}",
1259 merge_status.as_json(), 1260 merge_status.as_json(),
1260 ); 1261 );
@@ -1422,9 +1423,10 @@ async fn proposal_commits_applied_and_pushed_to_main_leads_to_status_event_issue
1422 .collect::<Vec<String>>() 1423 .collect::<Vec<String>>()
1423 { 1424 {
1424 assert!( 1425 assert!(
1425 merge_status.tags.iter().any(|t| t.as_slice().len().eq(&4) 1426 merge_status
1426 && t.as_slice()[1] == patch_id 1427 .tags
1427 && t.as_slice()[3].eq("mention")), 1428 .iter()
1429 .any(|t| t.as_slice()[0].eq("q") && t.as_slice()[1] == patch_id),
1428 "merge status doesnt mention proposal patch {patch_id} \r\nmerge status:\r\n{}", 1430 "merge status doesnt mention proposal patch {patch_id} \r\nmerge status:\r\n{}",
1429 merge_status.as_json(), 1431 merge_status.as_json(),
1430 ); 1432 );
diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs
index 2cd5956..9a46469 100644
--- a/tests/ngit_send.rs
+++ b/tests/ngit_send.rs
@@ -1759,9 +1759,8 @@ mod in_reply_to_mentions_issue {
1759 let cover_letter_event: &nostr::Event = 1759 let cover_letter_event: &nostr::Event =
1760 relay.events.iter().find(|e| is_cover_letter(e)).unwrap(); 1760 relay.events.iter().find(|e| is_cover_letter(e)).unwrap();
1761 assert!(cover_letter_event.tags.iter().any(|t| { 1761 assert!(cover_letter_event.tags.iter().any(|t| {
1762 t.as_slice()[0].eq("e") 1762 t.as_slice()[0].eq("q")
1763 && t.as_slice()[1].eq(&get_pretend_issue_event().id.to_hex()) 1763 && t.as_slice()[1].eq(&get_pretend_issue_event().id.to_hex())
1764 && t.as_slice()[3].eq(&"mention")
1765 })); 1764 }));
1766 } 1765 }
1767 Ok(()) 1766 Ok(())