upleb.uk

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

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/client.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-11-05 20:13:22 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-11-05 20:25:38 +0000
commit396da002fefeeb4549e11ff51abf824e91a6ed88 (patch)
treed5a61d081d97b52a38f7ce8f4a28d8c200eeede3 /grasp-audit/src/client.rs
parentb22cb23928ef799b0a5d362003d3084d2ab267b4 (diff)
restructure grasp01 audit tests and add event acceptance
Diffstat (limited to 'grasp-audit/src/client.rs')
-rw-r--r--grasp-audit/src/client.rs76
1 files changed, 76 insertions, 0 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs
index cbefeb9..aed3058 100644
--- a/grasp-audit/src/client.rs
+++ b/grasp-audit/src/client.rs
@@ -232,6 +232,82 @@ impl AuditClient {
232 232
233 Ok(event) 233 Ok(event)
234 } 234 }
235
236 /// Create an issue (kind 1621) that references a repository
237 ///
238 /// # Arguments
239 /// * `repo_event` - The repository announcement event to reference
240 /// * `issue_title` - The subject/title of the issue
241 /// * `content` - The issue content/description
242 /// * `additional_tags` - Optional additional tags (e.g., for quoting other events)
243 ///
244 /// # Returns
245 /// A built and signed Event ready to be sent to the relay
246 pub fn create_issue(
247 &self,
248 repo_event: &Event,
249 issue_title: &str,
250 content: &str,
251 additional_tags: Vec<Tag>,
252 ) -> Result<Event> {
253 // Extract repo_id from the d tag
254 let repo_id = repo_event.tags.iter()
255 .find(|t| t.kind() == TagKind::d())
256 .and_then(|t| t.content())
257 .ok_or_else(|| anyhow!("Repository event must have a 'd' tag"))?
258 .to_string();
259
260 let repo_pubkey = repo_event.pubkey;
261 let a_tag_value = format!("30617:{}:{}", repo_pubkey, repo_id);
262
263 let mut tags = vec![
264 Tag::custom(TagKind::custom("a"), vec![a_tag_value]),
265 Tag::custom(TagKind::custom("subject"), vec![issue_title]),
266 ];
267
268 // Add any additional tags
269 tags.extend(additional_tags);
270
271 self.event_builder(Kind::Custom(1621), content)
272 .tags(tags)
273 .build(self.keys())
274 .map_err(|e| anyhow!("Failed to build issue event: {}", e))
275 }
276
277 /// Create a NIP-22 comment (kind 1111) for an event
278 ///
279 /// # Arguments
280 /// * `event` - The event to comment on
281 /// * `content` - The comment content
282 /// * `additional_tags` - Optional additional tags
283 ///
284 /// # Returns
285 /// A built and signed Event ready to be sent to the relay
286 pub fn create_comment(
287 &self,
288 event: &Event,
289 content: &str,
290 additional_tags: Vec<Tag>,
291 ) -> Result<Event> {
292 let event_kind = event.kind;
293 let event_pubkey = event.pubkey;
294 let event_id = event.id;
295
296 let mut tags = vec![
297 Tag::custom(TagKind::custom("E"), vec![event_id.to_hex(), "".to_string(), "root".to_string()]),
298 Tag::event(event_id),
299 Tag::custom(TagKind::custom("K"), vec![event_kind.as_u16().to_string()]),
300 Tag::public_key(event_pubkey),
301 ];
302
303 // Add any additional tags
304 tags.extend(additional_tags);
305
306 self.event_builder(Kind::Custom(1111), content)
307 .tags(tags)
308 .build(self.keys())
309 .map_err(|e| anyhow!("Failed to build comment event: {}", e))
310 }
235} 311}
236 312
237#[cfg(test)] 313#[cfg(test)]