diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/git_events.rs | 202 |
1 files changed, 116 insertions, 86 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 7bca63b..7cd64ab 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -359,9 +359,25 @@ pub fn generate_unsigned_pr_or_update_event( | |||
| 359 | clone_url_hint: &[&str], | 359 | clone_url_hint: &[&str], |
| 360 | mentions: &[nostr::Tag], | 360 | mentions: &[nostr::Tag], |
| 361 | ) -> Result<UnsignedEvent> { | 361 | ) -> Result<UnsignedEvent> { |
| 362 | let title = git_repo.get_commit_message_summary(commit)?; | 362 | let root_patch_cover_letter = if let Some(root_proposal) = root_proposal { |
| 363 | if root_proposal.kind.eq(&Kind::GitPatch) { | ||
| 364 | Some(event_to_cover_letter(root_proposal)?) | ||
| 365 | } else { | ||
| 366 | None | ||
| 367 | } | ||
| 368 | } else { | ||
| 369 | None | ||
| 370 | }; | ||
| 363 | 371 | ||
| 364 | let description = { | 372 | let title = if let Some(cl) = &root_patch_cover_letter { |
| 373 | cl.title.clone() | ||
| 374 | } else { | ||
| 375 | git_repo.get_commit_message_summary(commit)? | ||
| 376 | }; | ||
| 377 | |||
| 378 | let description = if let Some(cl) = &root_patch_cover_letter { | ||
| 379 | cl.description.clone() | ||
| 380 | } else { | ||
| 365 | let mut description = git_repo.get_commit_message(commit)?.trim().to_string(); | 381 | let mut description = git_repo.get_commit_message(commit)?.trim().to_string(); |
| 366 | if let Some(remaining_description) = description.strip_prefix(&title) { | 382 | if let Some(remaining_description) = description.strip_prefix(&title) { |
| 367 | description = remaining_description.trim().to_string(); | 383 | description = remaining_description.trim().to_string(); |
| @@ -373,97 +389,111 @@ pub fn generate_unsigned_pr_or_update_event( | |||
| 373 | .get_root_commit() | 389 | .get_root_commit() |
| 374 | .context("failed to get root commit of the repository")?; | 390 | .context("failed to get root commit of the repository")?; |
| 375 | 391 | ||
| 376 | Ok(if root_proposal.is_some() { | 392 | let pr_update_specific_tags = |root_proposal: &Event| { |
| 377 | EventBuilder::new(KIND_PULL_REQUEST_UPDATE, "") | 393 | vec![ |
| 378 | } else { | 394 | Tag::custom( |
| 379 | EventBuilder::new(KIND_PULL_REQUEST, description) | 395 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")), |
| 380 | } | 396 | vec![format!("git Pull Request Update")], |
| 381 | .tags( | 397 | ), |
| 398 | Tag::custom( | ||
| 399 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("E")), | ||
| 400 | vec![root_proposal.id], | ||
| 401 | ), | ||
| 402 | Tag::custom( | ||
| 403 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("P")), | ||
| 404 | vec![root_proposal.pubkey], | ||
| 405 | ), | ||
| 406 | ] | ||
| 407 | }; | ||
| 408 | let pr_specific_tags = || { | ||
| 382 | [ | 409 | [ |
| 383 | repo_ref | ||
| 384 | .maintainers | ||
| 385 | .iter() | ||
| 386 | .map(|m| { | ||
| 387 | Tag::from_standardized(TagStandard::Coordinate { | ||
| 388 | coordinate: Coordinate { | ||
| 389 | kind: nostr::Kind::GitRepoAnnouncement, | ||
| 390 | public_key: *m, | ||
| 391 | identifier: repo_ref.identifier.to_string(), | ||
| 392 | }, | ||
| 393 | relay_url: repo_ref.relays.first().cloned(), | ||
| 394 | uppercase: false, | ||
| 395 | }) | ||
| 396 | }) | ||
| 397 | .collect::<Vec<Tag>>(), | ||
| 398 | mentions.to_vec(), | ||
| 399 | if let Some(root_proposal) = root_proposal { | ||
| 400 | [ | ||
| 401 | vec![Tag::custom( | ||
| 402 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")), | ||
| 403 | vec![format!("git Pull Request Update")], | ||
| 404 | )], | ||
| 405 | if root_proposal.kind.eq(&KIND_PULL_REQUEST) { | ||
| 406 | vec![ | ||
| 407 | Tag::custom( | ||
| 408 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("E")), | ||
| 409 | vec![root_proposal.id], | ||
| 410 | ), | ||
| 411 | Tag::custom( | ||
| 412 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("P")), | ||
| 413 | vec![root_proposal.pubkey], | ||
| 414 | ), | ||
| 415 | ] | ||
| 416 | } else { | ||
| 417 | // root proposal is a Patch - so use e tag per nip34 spec | ||
| 418 | vec![Tag::custom( | ||
| 419 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("e")), | ||
| 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![ | 410 | vec![ |
| 445 | Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))), | 411 | Tag::from_standardized(TagStandard::Subject(title.clone())), |
| 446 | Tag::custom( | ||
| 447 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("c")), | ||
| 448 | vec![format!("{commit}")], | ||
| 449 | ), | ||
| 450 | Tag::custom( | 412 | Tag::custom( |
| 451 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), | 413 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("alt")), |
| 452 | clone_url_hint | 414 | vec![format!("git Pull Request: {}", title.clone())], |
| 453 | .iter() | ||
| 454 | .map(|s| s.to_string()) | ||
| 455 | .collect::<Vec<String>>(), | ||
| 456 | ), | 415 | ), |
| 457 | ], | 416 | ], |
| 458 | repo_ref | 417 | if let Some(cl) = &root_patch_cover_letter { |
| 459 | .maintainers | 418 | vec![ |
| 460 | .iter() | 419 | Tag::custom( |
| 461 | .map(|pk| Tag::public_key(*pk)) | 420 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("e")), |
| 462 | .collect(), | 421 | vec![root_proposal.unwrap().id], |
| 422 | ), | ||
| 423 | Tag::custom( | ||
| 424 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("branch-name")), | ||
| 425 | vec![cl.branch_name_without_id_or_prefix.clone()], | ||
| 426 | ), | ||
| 427 | Tag::public_key(root_proposal.unwrap().pubkey), | ||
| 428 | ] | ||
| 429 | } else if let Some(branch_name_tag) = | ||
| 430 | make_branch_name_tag_from_check_out_branch(git_repo) | ||
| 431 | { | ||
| 432 | vec![branch_name_tag] | ||
| 433 | } else { | ||
| 434 | vec![] | ||
| 435 | }, | ||
| 463 | ] | 436 | ] |
| 464 | .concat(), | 437 | .concat() |
| 438 | }; | ||
| 439 | |||
| 440 | Ok( | ||
| 441 | if root_proposal.is_some() && root_patch_cover_letter.is_none() { | ||
| 442 | EventBuilder::new(KIND_PULL_REQUEST_UPDATE, "") | ||
| 443 | } else { | ||
| 444 | EventBuilder::new(KIND_PULL_REQUEST, description) | ||
| 445 | } | ||
| 446 | .tags( | ||
| 447 | [ | ||
| 448 | repo_ref | ||
| 449 | .maintainers | ||
| 450 | .iter() | ||
| 451 | .map(|m| { | ||
| 452 | Tag::from_standardized(TagStandard::Coordinate { | ||
| 453 | coordinate: Coordinate { | ||
| 454 | kind: nostr::Kind::GitRepoAnnouncement, | ||
| 455 | public_key: *m, | ||
| 456 | identifier: repo_ref.identifier.to_string(), | ||
| 457 | }, | ||
| 458 | relay_url: repo_ref.relays.first().cloned(), | ||
| 459 | uppercase: false, | ||
| 460 | }) | ||
| 461 | }) | ||
| 462 | .collect::<Vec<Tag>>(), | ||
| 463 | mentions.to_vec(), | ||
| 464 | if let Some(root_proposal) = root_proposal { | ||
| 465 | if root_patch_cover_letter.is_none() { | ||
| 466 | pr_update_specific_tags(root_proposal) | ||
| 467 | } else { | ||
| 468 | pr_specific_tags() | ||
| 469 | } | ||
| 470 | } else { | ||
| 471 | pr_specific_tags() | ||
| 472 | }, | ||
| 473 | vec![ | ||
| 474 | Tag::from_standardized(TagStandard::Reference(format!("{root_commit}"))), | ||
| 475 | Tag::custom( | ||
| 476 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("c")), | ||
| 477 | vec![format!("{commit}")], | ||
| 478 | ), | ||
| 479 | Tag::custom( | ||
| 480 | nostr::TagKind::Custom(std::borrow::Cow::Borrowed("clone")), | ||
| 481 | clone_url_hint | ||
| 482 | .iter() | ||
| 483 | .map(|s| s.to_string()) | ||
| 484 | .collect::<Vec<String>>(), | ||
| 485 | ), | ||
| 486 | ], | ||
| 487 | repo_ref | ||
| 488 | .maintainers | ||
| 489 | .iter() | ||
| 490 | .map(|pk| Tag::public_key(*pk)) | ||
| 491 | .collect(), | ||
| 492 | ] | ||
| 493 | .concat(), | ||
| 494 | ) | ||
| 495 | .build(*signing_public_key), | ||
| 465 | ) | 496 | ) |
| 466 | .build(*signing_public_key)) | ||
| 467 | } | 497 | } |
| 468 | 498 | ||
| 469 | fn make_branch_name_tag_from_check_out_branch(git_repo: &Repo) -> Option<Tag> { | 499 | fn make_branch_name_tag_from_check_out_branch(git_repo: &Repo) -> Option<Tag> { |