diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-04 16:24:29 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-04 16:24:29 +0000 |
| commit | af016dd23101537ccc8ecd5a992bf3b7c6d3abe9 (patch) | |
| tree | 15284c3a1301ea738507beadd2687d4dd0d248b5 /src/bin/ngit/sub_commands/comment.rs | |
| parent | 293ef01e141846f7de5af2c8c6be9d6c694083fd (diff) | |
add NIP-21 content tags (q/p) to issues, comments, PRs and patches
- parse nostr: URI mentions in issue bodies, comment bodies, PR
descriptions, patch commit messages and cover letters
- npub/nprofile mentions produce p tags; note/nevent/naddr mentions
produce q tags per NIP-22
- naddr q tag value uses raw <kind>:<pubkey-hex>:<identifier> format
- nevent pubkey field populated from embedded author or local cache lookup
- dedup_tags() removes duplicate p tags and suppresses q tags whose
event-id is already covered by an existing e threading tag
- all parsing errors are non-fatal: invalid nostr: tokens are skipped
Diffstat (limited to 'src/bin/ngit/sub_commands/comment.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/comment.rs | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/bin/ngit/sub_commands/comment.rs b/src/bin/ngit/sub_commands/comment.rs index c47a1f0..60626e5 100644 --- a/src/bin/ngit/sub_commands/comment.rs +++ b/src/bin/ngit/sub_commands/comment.rs | |||
| @@ -4,6 +4,7 @@ use ngit::{ | |||
| 4 | Params, get_events_from_local_cache, get_issues_from_cache, | 4 | Params, get_events_from_local_cache, get_issues_from_cache, |
| 5 | get_proposals_and_revisions_from_cache, send_events, sign_event, | 5 | get_proposals_and_revisions_from_cache, send_events, sign_event, |
| 6 | }, | 6 | }, |
| 7 | content_tags::{dedup_tags, tags_from_content}, | ||
| 7 | git_events::KIND_COMMENT, | 8 | git_events::KIND_COMMENT, |
| 8 | }; | 9 | }; |
| 9 | use nostr::{EventBuilder, Tag, nips::nip19::Nip19}; | 10 | use nostr::{EventBuilder, Tag, nips::nip19::Nip19}; |
| @@ -102,36 +103,43 @@ async fn publish_comment(args: CommentArgs<'_>) -> Result<()> { | |||
| 102 | let root_kind_str = root_kind.as_u16().to_string(); | 103 | let root_kind_str = root_kind.as_u16().to_string(); |
| 103 | let parent_kind_str = parent_kind.as_u16().to_string(); | 104 | let parent_kind_str = parent_kind.as_u16().to_string(); |
| 104 | 105 | ||
| 105 | // NIP-22 compliant tags | 106 | // NIP-22 compliant threading tags |
| 107 | let mut comment_tags: Vec<Tag> = vec![ | ||
| 108 | // Root scope: uppercase E with root pubkey as 4th element | ||
| 109 | Tag::parse(vec![ | ||
| 110 | "E".to_string(), | ||
| 111 | root_event_id.to_hex(), | ||
| 112 | relay_hint.clone(), | ||
| 113 | root_pubkey.to_hex(), | ||
| 114 | ])?, | ||
| 115 | // Root kind | ||
| 116 | Tag::parse(vec!["K".to_string(), root_kind_str])?, | ||
| 117 | // Root author pubkey | ||
| 118 | Tag::parse(vec![ | ||
| 119 | "P".to_string(), | ||
| 120 | root_pubkey.to_hex(), | ||
| 121 | relay_hint.clone(), | ||
| 122 | ])?, | ||
| 123 | // Parent item: lowercase e with parent pubkey as 4th element | ||
| 124 | Tag::parse(vec![ | ||
| 125 | "e".to_string(), | ||
| 126 | parent_event_id.to_hex(), | ||
| 127 | relay_hint.clone(), | ||
| 128 | parent_pubkey.to_hex(), | ||
| 129 | ])?, | ||
| 130 | // Parent kind | ||
| 131 | Tag::parse(vec!["k".to_string(), parent_kind_str])?, | ||
| 132 | // Parent author pubkey | ||
| 133 | Tag::parse(vec!["p".to_string(), parent_pubkey.to_hex(), relay_hint])?, | ||
| 134 | ]; | ||
| 135 | |||
| 136 | // NIP-21 mention tags: q tags for cited events/addresses, p tags for cited | ||
| 137 | // pubkeys | ||
| 138 | comment_tags.extend(tags_from_content(body, Some(git_repo_path)).await?); | ||
| 139 | let comment_tags = dedup_tags(comment_tags); | ||
| 140 | |||
| 106 | let comment_event = sign_event( | 141 | let comment_event = sign_event( |
| 107 | EventBuilder::new(KIND_COMMENT, body).tags(vec![ | 142 | EventBuilder::new(KIND_COMMENT, body).tags(comment_tags), |
| 108 | // Root scope: uppercase E with root pubkey as 4th element | ||
| 109 | Tag::parse(vec![ | ||
| 110 | "E".to_string(), | ||
| 111 | root_event_id.to_hex(), | ||
| 112 | relay_hint.clone(), | ||
| 113 | root_pubkey.to_hex(), | ||
| 114 | ])?, | ||
| 115 | // Root kind | ||
| 116 | Tag::parse(vec!["K".to_string(), root_kind_str])?, | ||
| 117 | // Root author pubkey | ||
| 118 | Tag::parse(vec![ | ||
| 119 | "P".to_string(), | ||
| 120 | root_pubkey.to_hex(), | ||
| 121 | relay_hint.clone(), | ||
| 122 | ])?, | ||
| 123 | // Parent item: lowercase e with parent pubkey as 4th element | ||
| 124 | Tag::parse(vec![ | ||
| 125 | "e".to_string(), | ||
| 126 | parent_event_id.to_hex(), | ||
| 127 | relay_hint.clone(), | ||
| 128 | parent_pubkey.to_hex(), | ||
| 129 | ])?, | ||
| 130 | // Parent kind | ||
| 131 | Tag::parse(vec!["k".to_string(), parent_kind_str])?, | ||
| 132 | // Parent author pubkey | ||
| 133 | Tag::parse(vec!["p".to_string(), parent_pubkey.to_hex(), relay_hint])?, | ||
| 134 | ]), | ||
| 135 | &signer, | 143 | &signer, |
| 136 | format!("comment on {entity_name}"), | 144 | format!("comment on {entity_name}"), |
| 137 | ) | 145 | ) |