upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git_events.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/git_events.rs')
-rw-r--r--src/lib/git_events.rs143
1 files changed, 91 insertions, 52 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs
index 86b9641..7bca63b 100644
--- a/src/lib/git_events.rs
+++ b/src/lib/git_events.rs
@@ -350,10 +350,11 @@ pub fn event_tag_from_nip19_or_hex(
350 } 350 }
351} 351}
352 352
353pub fn generate_unsigned_pr_event( 353pub fn generate_unsigned_pr_or_update_event(
354 git_repo: &Repo, 354 git_repo: &Repo,
355 repo_ref: &RepoRef, 355 repo_ref: &RepoRef,
356 signing_public_key: &PublicKey, 356 signing_public_key: &PublicKey,
357 root_proposal: Option<&Event>,
357 commit: &Sha1Hash, 358 commit: &Sha1Hash,
358 clone_url_hint: &[&str], 359 clone_url_hint: &[&str],
359 mentions: &[nostr::Tag], 360 mentions: &[nostr::Tag],
@@ -372,59 +373,97 @@ pub fn generate_unsigned_pr_event(
372 .get_root_commit() 373 .get_root_commit()
373 .context("failed to get root commit of the repository")?; 374 .context("failed to get root commit of the repository")?;
374 375
375 Ok(EventBuilder::new(KIND_PULL_REQUEST, description) 376 Ok(if root_proposal.is_some() {
376 .tags( 377 EventBuilder::new(KIND_PULL_REQUEST_UPDATE, "")
377 [ 378 } else {
378 repo_ref 379 EventBuilder::new(KIND_PULL_REQUEST, description)
379 .maintainers 380 }
380 .iter() 381 .tags(
381 .map(|m| { 382 [
382 Tag::from_standardized(TagStandard::Coordinate { 383 repo_ref
383 coordinate: Coordinate { 384 .maintainers
384 kind: nostr::Kind::GitRepoAnnouncement, 385 .iter()
385 public_key: *m, 386 .map(|m| {
386 identifier: repo_ref.identifier.to_string(), 387 Tag::from_standardized(TagStandard::Coordinate {
387 }, 388 coordinate: Coordinate {
388 relay_url: repo_ref.relays.first().cloned(), 389 kind: nostr::Kind::GitRepoAnnouncement,
389 uppercase: false, 390 public_key: *m,
390 }) 391 identifier: repo_ref.identifier.to_string(),
392 },
393 relay_url: repo_ref.relays.first().cloned(),
394 uppercase: false,
391 }) 395 })
392 .collect::<Vec<Tag>>(), 396 })
393 mentions.to_vec(), 397 .collect::<Vec<Tag>>(),
394 vec![ 398 mentions.to_vec(),
395 Tag::from_standardized(TagStandard::Subject(title.clone())), 399 if let Some(root_proposal) = root_proposal {
396 Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))), 400 [
397 Tag::custom( 401 vec![Tag::custom(
398 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("c")),
399 vec![format!("{commit}")],
400 ),
401 Tag::custom(
402 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")),
403 clone_url_hint
404 .iter()
405 .map(|s| s.to_string())
406 .collect::<Vec<String>>(),
407 ),
408 Tag::custom(
409 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")), 402 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")),
410 vec![format!("git Pull Request: {}", title.clone())], 403 vec![format!("git Pull Request Update")],
411 ), 404 )],
412 ], 405 if root_proposal.kind.eq(&KIND_PULL_REQUEST) {
413 if let Some(branch_name_tag) = make_branch_name_tag_from_check_out_branch(git_repo) 406 vec![
414 { 407 Tag::custom(
415 vec![branch_name_tag] 408 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("E")),
416 } else { 409 vec![root_proposal.id],
417 vec![] 410 ),
418 }, 411 Tag::custom(
419 repo_ref 412 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("P")),
420 .maintainers 413 vec![root_proposal.pubkey],
421 .iter() 414 ),
422 .map(|pk| Tag::public_key(*pk)) 415 ]
423 .collect(), 416 } else {
424 ] 417 // root proposal is a Patch - so use e tag per nip34 spec
425 .concat(), 418 vec![Tag::custom(
426 ) 419 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("e")),
427 .build(*signing_public_key)) 420 vec![root_proposal.id],
421 )]
422 },
423 ]
424 .concat()
425 } else {
426 [
427 vec![
428 Tag::from_standardized(TagStandard::Subject(title.clone())),
429 Tag::custom(
430 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")),
431 vec![format!("git Pull Request: {}", title.clone())],
432 ),
433 ],
434 if let Some(branch_name_tag) =
435 make_branch_name_tag_from_check_out_branch(git_repo)
436 {
437 vec![branch_name_tag]
438 } else {
439 vec![]
440 },
441 ]
442 .concat()
443 },
444 vec![
445 Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))),
446 Tag::custom(
447 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("c")),
448 vec![format!("{commit}")],
449 ),
450 Tag::custom(
451 nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")),
452 clone_url_hint
453 .iter()
454 .map(|s| s.to_string())
455 .collect::<Vec<String>>(),
456 ),
457 ],
458 repo_ref
459 .maintainers
460 .iter()
461 .map(|pk| Tag::public_key(*pk))
462 .collect(),
463 ]
464 .concat(),
465 )
466 .build(*signing_public_key))
428} 467}
429 468
430fn make_branch_name_tag_from_check_out_branch(git_repo: &Repo) -> Option<Tag> { 469fn make_branch_name_tag_from_check_out_branch(git_repo: &Repo) -> Option<Tag> {