upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-02-02 03:11:31 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-02-02 03:11:31 +0000
commit401e60b98d94bc1f51dbd4b6083e92642a36efda (patch)
treea4a78c4dc1fc291771f41994af4cf53be3aa6cf2 /src
parent1cacf1bce77b88febc0cf9e2f0f9f468d4b30555 (diff)
feat(repo_ref)!: align maintainers tag to nip34 style
nip34 specifies that repo event tags with multiple values wuch as "relays" and "web" use theformat: `["tag", "item", "item"...]` instead of: ``` ["tag", "item"], ["tag", "item"], ``` this update also adds clarity. it is not obvious that using a p tag is intended to make the pubkey a co-maintainer. BREAKING CHANGE: format of maintainers tags in repo events has changed to reflect nip34 style and ngit will not detect the old format
Diffstat (limited to 'src')
-rw-r--r--src/repo_ref.rs45
1 files changed, 25 insertions, 20 deletions
diff --git a/src/repo_ref.rs b/src/repo_ref.rs
index 1ec0ece..87c5b75 100644
--- a/src/repo_ref.rs
+++ b/src/repo_ref.rs
@@ -69,13 +69,19 @@ impl TryFrom<nostr::Event> for RepoRef {
69 r.relays.remove(0); 69 r.relays.remove(0);
70 } 70 }
71 71
72 for tag in event.tags.iter().filter(|t| t.as_vec()[0].eq("p")) { 72 if let Some(t) = event.tags.iter().find(|t| t.as_vec()[0].eq("maintainers")) {
73 let pk = tag.as_vec()[1].clone(); 73 let mut maintainers = t.as_vec().clone();
74 r.maintainers.push( 74 maintainers.remove(0);
75 if !maintainers.contains(&event.pubkey.to_string()) {
76 r.maintainers.push(event.pubkey);
77 }
78 for pk in maintainers {
79 r.maintainers.push(
75 nostr_sdk::prelude::XOnlyPublicKey::from_str(&pk) 80 nostr_sdk::prelude::XOnlyPublicKey::from_str(&pk)
76 .context(format!("cannot convert {pk} into a valid nostr public key")) 81 .context(format!("cannot convert entry from maintainers tag {pk} into a valid nostr public key. it should be in hex format"))
77 .context("invalid repository event")?, 82 .context("invalid repository event")?,
78 ); 83 );
84 }
79 } 85 }
80 86
81 Ok(r) 87 Ok(r)
@@ -121,15 +127,14 @@ impl RepoRef {
121 nostr::TagKind::Custom("relays".to_string()), 127 nostr::TagKind::Custom("relays".to_string()),
122 self.relays.clone(), 128 self.relays.clone(),
123 ), 129 ),
130 Tag::Generic(
131 nostr::TagKind::Custom("maintainers".to_string()),
132 self.maintainers
133 .iter()
134 .map(std::string::ToString::to_string)
135 .collect(),
136 ),
124 ], 137 ],
125 // this appears like a number of relay tags but test suggest is is actually
126 // what we want which is a relays tag with lots of values. no need for the
127 // change?
128 // self.relays.iter().map(|r| Tag::Relay(r.into())).collect(),
129 self.maintainers
130 .iter()
131 .map(|pk| Tag::public_key(*pk))
132 .collect(),
133 // code languages and hashtags 138 // code languages and hashtags
134 ] 139 ]
135 .concat(), 140 .concat(),
@@ -451,25 +456,25 @@ mod tests {
451 #[test] 456 #[test]
452 fn maintainers() { 457 fn maintainers() {
453 let event = create(); 458 let event = create();
454 let p_tags = event 459 let maintainers_tag: &nostr::Tag = event
455 .tags 460 .tags
456 .iter() 461 .iter()
457 .filter(|t| t.as_vec()[0].eq("p")) 462 .find(|t| t.as_vec()[0].eq("maintainers"))
458 .collect::<Vec<&nostr::Tag>>(); 463 .unwrap();
459 assert_eq!(p_tags[0].as_vec().len(), 2); 464 assert_eq!(maintainers_tag.as_vec().len(), 3);
460 assert_eq!( 465 assert_eq!(
461 p_tags[0].as_vec()[1], 466 maintainers_tag.as_vec()[1],
462 TEST_KEY_1_KEYS.public_key().to_string() 467 TEST_KEY_1_KEYS.public_key().to_string()
463 ); 468 );
464 assert_eq!( 469 assert_eq!(
465 p_tags[1].as_vec()[1], 470 maintainers_tag.as_vec()[2],
466 TEST_KEY_2_KEYS.public_key().to_string() 471 TEST_KEY_2_KEYS.public_key().to_string()
467 ); 472 );
468 } 473 }
469 474
470 #[test] 475 #[test]
471 fn no_other_tags() { 476 fn no_other_tags() {
472 assert_eq!(create().tags.len(), 9) 477 assert_eq!(create().tags.len(), 8)
473 } 478 }
474 } 479 }
475 } 480 }