diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 12:50:03 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-05 12:50:03 +0000 |
| commit | 64a86de9fc5ded51a1b5405223fc5dce16839fef (patch) | |
| tree | 9c981e337d3c3908776aa41c1eaff6c3e44cba14 /grasp-audit/src/client.rs | |
| parent | 94bf5c39af0d8d0a9a15db240d5d46383ec22160 (diff) | |
Refactor: abstract announcement event creation into AuditClient helper
- Add create_repo_announcement() method to AuditClient
- Remove duplicate code from nip01_smoke.rs
- Update grasp01_nostr_relay.rs to use centralized helper
- All tests passing (GRASP-01: 4/18, NIP-01: 6/6)
Diffstat (limited to 'grasp-audit/src/client.rs')
| -rw-r--r-- | grasp-audit/src/client.rs | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/grasp-audit/src/client.rs b/grasp-audit/src/client.rs index b80b59f..7706ee3 100644 --- a/grasp-audit/src/client.rs +++ b/grasp-audit/src/client.rs | |||
| @@ -158,6 +158,49 @@ impl AuditClient { | |||
| 158 | pub fn keys(&self) -> &Keys { | 158 | pub fn keys(&self) -> &Keys { |
| 159 | &self.keys | 159 | &self.keys |
| 160 | } | 160 | } |
| 161 | |||
| 162 | /// Create a NIP-34 repository announcement event | ||
| 163 | /// | ||
| 164 | /// This helper creates a properly formatted NIP-34 announcement that will be | ||
| 165 | /// accepted by GRASP relays (which require events to list the relay in clone/relays tags). | ||
| 166 | /// | ||
| 167 | /// # Arguments | ||
| 168 | /// * `test_name` - Name of the test (used to create unique repo identifier) | ||
| 169 | /// | ||
| 170 | /// # Returns | ||
| 171 | /// A built and signed Event ready to be sent to the relay | ||
| 172 | pub async fn create_repo_announcement(&self, test_name: &str) -> Result<Event> { | ||
| 173 | // Get relay URL from client | ||
| 174 | let relay_url = self.client.relays().await | ||
| 175 | .keys() | ||
| 176 | .next() | ||
| 177 | .ok_or_else(|| anyhow!("No relay connected"))? | ||
| 178 | .to_string(); | ||
| 179 | |||
| 180 | // Convert WebSocket URL to HTTP URL for clone tag | ||
| 181 | let http_url = relay_url | ||
| 182 | .replace("ws://", "http://") | ||
| 183 | .replace("wss://", "https://"); | ||
| 184 | |||
| 185 | // Create unique repository identifier using UUID for consistency | ||
| 186 | let repo_id = format!("{}-{}", test_name, uuid::Uuid::new_v4()); | ||
| 187 | |||
| 188 | // Get npub for clone URL | ||
| 189 | let npub = self.public_key().to_bech32() | ||
| 190 | .map_err(|e| anyhow!("Failed to convert public key to bech32 npub format: {}", e))?; | ||
| 191 | |||
| 192 | // Build kind 30617 repository announcement | ||
| 193 | let event = self.event_builder(Kind::GitRepoAnnouncement, format!("Test repository for {}", test_name)) | ||
| 194 | .tag(Tag::identifier(&repo_id)) | ||
| 195 | .tag(Tag::custom(TagKind::custom("name"), vec![format!("{} Test Repository", test_name)])) | ||
| 196 | .tag(Tag::custom(TagKind::custom("description"), vec![format!("Repository for {} testing", test_name)])) | ||
| 197 | .tag(Tag::custom(TagKind::custom("clone"), vec![format!("{}/{}/{}.git", http_url, npub, repo_id)])) | ||
| 198 | .tag(Tag::custom(TagKind::custom("relays"), vec![relay_url.clone()])) | ||
| 199 | .build(self.keys()) | ||
| 200 | .map_err(|e| anyhow!("Failed to build repository announcement event: {}", e))?; | ||
| 201 | |||
| 202 | Ok(event) | ||
| 203 | } | ||
| 161 | } | 204 | } |
| 162 | 205 | ||
| 163 | #[cfg(test)] | 206 | #[cfg(test)] |