diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-26 08:45:16 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-26 09:56:44 +0000 |
| commit | a6edb42dfc653b6826b59b7f296e0d0c4ee74557 (patch) | |
| tree | 4355445d8d51672cbf1dd86af0a4bd2ffcde1a7a /src | |
| parent | 30411a938d072a59d68815c975735d40366ad874 (diff) | |
fix: parsing maintainers from announcement event
Diffstat (limited to 'src')
| -rw-r--r-- | src/git/authorization.rs | 13 | ||||
| -rw-r--r-- | src/nostr/events.rs | 24 |
2 files changed, 26 insertions, 11 deletions
diff --git a/src/git/authorization.rs b/src/git/authorization.rs index 06672c8..2fe81b0 100644 --- a/src/git/authorization.rs +++ b/src/git/authorization.rs | |||
| @@ -444,11 +444,16 @@ mod tests { | |||
| 444 | ) -> Event { | 444 | ) -> Event { |
| 445 | let mut tags = vec![Tag::custom(TagKind::d(), vec![identifier.to_string()])]; | 445 | let mut tags = vec![Tag::custom(TagKind::d(), vec![identifier.to_string()])]; |
| 446 | 446 | ||
| 447 | // Add maintainers as p tags | 447 | // Add maintainers as a single "maintainers" tag per NIP-34 |
| 448 | for maintainer_keys in maintainers { | 448 | // Format: ["maintainers", "<pubkey1-hex>", "<pubkey2-hex>", ...] |
| 449 | if !maintainers.is_empty() { | ||
| 450 | let maintainer_pubkeys: Vec<String> = maintainers | ||
| 451 | .iter() | ||
| 452 | .map(|k| k.public_key().to_hex()) | ||
| 453 | .collect(); | ||
| 449 | tags.push(Tag::custom( | 454 | tags.push(Tag::custom( |
| 450 | TagKind::p(), | 455 | TagKind::Custom("maintainers".into()), |
| 451 | vec![maintainer_keys.public_key().to_hex()], | 456 | maintainer_pubkeys, |
| 452 | )); | 457 | )); |
| 453 | } | 458 | } |
| 454 | 459 | ||
diff --git a/src/nostr/events.rs b/src/nostr/events.rs index ddbb8f0..643269a 100644 --- a/src/nostr/events.rs +++ b/src/nostr/events.rs | |||
| @@ -105,14 +105,19 @@ impl RepositoryAnnouncement { | |||
| 105 | }) | 105 | }) |
| 106 | .collect(); | 106 | .collect(); |
| 107 | 107 | ||
| 108 | // Extract maintainers (other-user tags) | 108 | // Extract maintainers from "maintainers" tag per NIP-34 |
| 109 | // Format: ["maintainers", "<pubkey1-hex>", "<pubkey2-hex>", ...] | ||
| 109 | let maintainers = event | 110 | let maintainers = event |
| 110 | .tags | 111 | .tags |
| 111 | .iter() | 112 | .iter() |
| 112 | .filter(|t| t.kind() == TagKind::p()) | 113 | .find(|tag| tag.as_slice().first().map(|s| s.as_str()) == Some("maintainers")) |
| 113 | .filter_map(|t| t.content()) | 114 | .map(|tag| { |
| 114 | .map(|s| s.to_string()) | 115 | tag.as_slice()[1..] // Skip the "maintainers" tag name |
| 115 | .collect(); | 116 | .iter() |
| 117 | .map(|s| s.to_string()) | ||
| 118 | .collect() | ||
| 119 | }) | ||
| 120 | .unwrap_or_default(); | ||
| 116 | 121 | ||
| 117 | Ok(RepositoryAnnouncement { | 122 | Ok(RepositoryAnnouncement { |
| 118 | event, | 123 | event, |
| @@ -546,8 +551,12 @@ mod tests { | |||
| 546 | ), | 551 | ), |
| 547 | ]; | 552 | ]; |
| 548 | 553 | ||
| 549 | // Add maintainer | 554 | // Add maintainer using NIP-34 "maintainers" tag format |
| 550 | tags.push(Tag::public_key(maintainer_keys.public_key())); | 555 | // Format: ["maintainers", "<pubkey1-hex>", "<pubkey2-hex>", ...] |
| 556 | tags.push(Tag::custom( | ||
| 557 | nostr_sdk::TagKind::Custom("maintainers".into()), | ||
| 558 | vec![maintainer_keys.public_key().to_hex()], | ||
| 559 | )); | ||
| 551 | 560 | ||
| 552 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repository") | 561 | let event = EventBuilder::new(Kind::from(KIND_REPOSITORY_ANNOUNCEMENT), "Test repository") |
| 553 | .tags(tags) | 562 | .tags(tags) |
| @@ -556,6 +565,7 @@ mod tests { | |||
| 556 | 565 | ||
| 557 | let announcement = RepositoryAnnouncement::from_event(event).unwrap(); | 566 | let announcement = RepositoryAnnouncement::from_event(event).unwrap(); |
| 558 | assert_eq!(announcement.maintainers.len(), 1); | 567 | assert_eq!(announcement.maintainers.len(), 1); |
| 568 | assert_eq!(announcement.maintainers[0], maintainer_keys.public_key().to_hex()); | ||
| 559 | } | 569 | } |
| 560 | 570 | ||
| 561 | #[test] | 571 | #[test] |