upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/nostr/builder.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-31 09:18:21 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-31 10:49:09 +0000
commit768fe91caa676e4501aa26e14e01ca47f3ea4ca1 (patch)
treee697becb6b2253909d399073f5c2bd2d571fcf5e /src/nostr/builder.rs
parent3d6901831904141166d9ed8f47813c45cba109b6 (diff)
purgatory: fix pr event recieve code
Diffstat (limited to 'src/nostr/builder.rs')
-rw-r--r--src/nostr/builder.rs71
1 files changed, 52 insertions, 19 deletions
diff --git a/src/nostr/builder.rs b/src/nostr/builder.rs
index 37fa025..3d7a0d8 100644
--- a/src/nostr/builder.rs
+++ b/src/nostr/builder.rs
@@ -168,8 +168,54 @@ impl Nip34WritePolicy {
168 async fn handle_pr_event(&self, event: &Event) -> WritePolicyResult { 168 async fn handle_pr_event(&self, event: &Event) -> WritePolicyResult {
169 let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex()); 169 let event_id_str = event.id.to_bech32().unwrap_or_else(|_| event.id.to_hex());
170 170
171 // Check if git data exists (checks placeholders and commit existence) 171 // duplicate check in purgatory
172 match self.pr_event_policy.check_git_data_exists(event).await { 172 let in_purgatory = self
173 .ctx
174 .purgatory
175 .find_pr(&event.id.to_hex())
176 .is_some_and(|e| e.event.is_some());
177 if in_purgatory {
178 tracing::debug!(
179 "processed PR event duplicate (already in purgatory): {}",
180 event.id,
181 );
182 return WritePolicyResult::Reject {
183 status: true, // Client sees OK
184 message: "duplicate: in purgatory".into(),
185 };
186 }
187
188 // duplicate check in db
189 match &self.ctx.database.check_id(&event.id).await {
190 Ok(DatabaseEventStatus::Saved) => {
191 return WritePolicyResult::Reject {
192 status: true, // Client sees OK
193 message: "duplicate".into(),
194 };
195 }
196 Ok(DatabaseEventStatus::Deleted) => {
197 return WritePolicyResult::Reject {
198 status: false,
199 message: "invalid: accepted deletion request for this event".into(),
200 };
201 }
202 Err(e) => {
203 return WritePolicyResult::Reject {
204 status: false,
205 message: format!("error: internal error: {e}").into(),
206 };
207 }
208 _ => {} // continue
209 }
210
211 // Reject PRs unrelated to stored repositories / events
212 match self.handle_related_event(event, "PR").await {
213 WritePolicyResult::Accept => {} // continue
214 rejected => return rejected,
215 }
216
217 // Check if git data exists (delete any incorrect commits at refs/nostr/<event-id>, copies correct data to relivant repositories)
218 match self.pr_event_policy.git_data_check(event).await {
173 Ok(false) => { 219 Ok(false) => {
174 // No git data exists - add to purgatory 220 // No git data exists - add to purgatory
175 let commit = event 221 let commit = event
@@ -196,18 +242,19 @@ impl Nip34WritePolicy {
196 .purgatory 242 .purgatory
197 .add_pr(event.clone(), event.id.to_hex(), commit.clone()); 243 .add_pr(event.clone(), event.id.to_hex(), commit.clone());
198 244
199 return WritePolicyResult::Reject { 245 WritePolicyResult::Reject {
200 status: true, // Client sees OK 246 status: true, // Client sees OK
201 message: format!( 247 message: format!(
202 "purgatory: PR event stored, waiting for git push with commit {}", 248 "purgatory: PR event stored, waiting for git push with commit {}",
203 commit 249 commit
204 ) 250 )
205 .into(), 251 .into(),
206 }; 252 }
207 } 253 }
208 Ok(true) => { 254 Ok(true) => {
209 // Git data exists - proceed with normal validation 255 // Git data exists - proceed with normal validation
210 tracing::debug!("Git data exists for PR event {}", event_id_str); 256 tracing::debug!("Git data exists for PR event {}", event_id_str);
257 WritePolicyResult::Accept
211 } 258 }
212 Err(e) => { 259 Err(e) => {
213 // Error checking git data - reject event 260 // Error checking git data - reject event
@@ -216,23 +263,9 @@ impl Nip34WritePolicy {
216 event_id_str, 263 event_id_str,
217 e 264 e
218 ); 265 );
219 return WritePolicyResult::reject(format!("Failed to check git data: {}", e)); 266 WritePolicyResult::reject(format!("Failed to check git data: {}", e))
220 } 267 }
221 } 268 }
222
223 // Validate refs/nostr refs for this PR event
224 // This deletes any refs/nostr/<event-id> that points to wrong commit
225 if let Err(e) = self.pr_event_policy.validate_nostr_ref(event).await {
226 tracing::warn!(
227 "Failed to validate refs/nostr for PR event {}: {}",
228 event_id_str,
229 e
230 );
231 // Don't reject - just log the error and proceed with normal validation
232 }
233
234 // Continue with reference checking (same as related events)
235 self.handle_related_event(event, "PR").await
236 } 269 }
237 270
238 /// Handle events that must reference accepted repositories or events 271 /// Handle events that must reference accepted repositories or events