diff options
Diffstat (limited to 'src/lib/git_events.rs')
| -rw-r--r-- | src/lib/git_events.rs | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 80793bd..7b25daf 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -70,11 +70,16 @@ pub fn event_is_patch_set_root(event: &Event) -> bool { | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | pub fn event_is_revision_root(event: &Event) -> bool { | 72 | pub fn event_is_revision_root(event: &Event) -> bool { |
| 73 | event.kind.eq(&Kind::GitPatch) | 73 | (event.kind.eq(&Kind::GitPatch) |
| 74 | && event | 74 | && event |
| 75 | .tags | 75 | .tags |
| 76 | .iter() | 76 | .iter() |
| 77 | .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("revision-root")) | 77 | .any(|t| t.as_slice().len() > 1 && t.as_slice()[1].eq("revision-root"))) |
| 78 | || (event.kind.eq(&KIND_PULL_REQUEST) | ||
| 79 | && event | ||
| 80 | .tags | ||
| 81 | .iter() | ||
| 82 | .any(|t| t.as_slice().len() > 1 && t.as_slice()[0].eq("e"))) | ||
| 78 | } | 83 | } |
| 79 | 84 | ||
| 80 | pub fn patch_supports_commit_ids(event: &Event) -> bool { | 85 | pub fn patch_supports_commit_ids(event: &Event) -> bool { |
| @@ -534,13 +539,22 @@ pub fn commit_msg_from_patch_oneliner(patch: &nostr::Event) -> Result<String> { | |||
| 534 | } | 539 | } |
| 535 | 540 | ||
| 536 | pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { | 541 | pub fn event_to_cover_letter(event: &nostr::Event) -> Result<CoverLetter> { |
| 537 | if !event_is_patch_set_root(event) { | 542 | if !event.kind.eq(&KIND_PULL_REQUEST) && !event_is_patch_set_root(event) { |
| 538 | bail!("event is not a patch set root event (root patch or cover letter)") | 543 | bail!("event is not a patch set root event (root patch or cover letter)") |
| 539 | } | 544 | } |
| 540 | 545 | ||
| 541 | let title = commit_msg_from_patch_oneliner(event)?; | 546 | let title = if event.kind.eq(&KIND_PULL_REQUEST) { |
| 542 | let full = commit_msg_from_patch(event)?; | 547 | tag_value(event, "subject").unwrap_or("untitled".to_owned()) |
| 543 | let description = full[title.len()..].trim().to_string(); | 548 | } else { |
| 549 | commit_msg_from_patch_oneliner(event)? | ||
| 550 | }; | ||
| 551 | let description = if event.kind.eq(&KIND_PULL_REQUEST) { | ||
| 552 | event.content.clone() | ||
| 553 | } else { | ||
| 554 | commit_msg_from_patch(event)?[title.len()..] | ||
| 555 | .trim() | ||
| 556 | .to_string() | ||
| 557 | }; | ||
| 544 | 558 | ||
| 545 | Ok(CoverLetter { | 559 | Ok(CoverLetter { |
| 546 | title: title.clone(), | 560 | title: title.clone(), |
| @@ -572,25 +586,25 @@ fn safe_branch_name_for_pr(s: &str) -> String { | |||
| 572 | .collect() | 586 | .collect() |
| 573 | } | 587 | } |
| 574 | 588 | ||
| 575 | pub fn get_most_recent_patch_with_ancestors( | 589 | pub fn get_pr_tip_event_or_most_recent_patch_with_ancestors( |
| 576 | mut patches: Vec<nostr::Event>, | 590 | mut proposal_events: Vec<nostr::Event>, |
| 577 | ) -> Result<Vec<nostr::Event>> { | 591 | ) -> Result<Vec<nostr::Event>> { |
| 578 | patches.sort_by_key(|e| e.created_at); | 592 | proposal_events.sort_by_key(|e| e.created_at); |
| 579 | 593 | ||
| 580 | let youngest_patch = patches.last().context("no patches found")?; | 594 | let youngest = proposal_events.last().context("no proposal events found")?; |
| 581 | 595 | ||
| 582 | let patches_with_youngest_created_at: Vec<&nostr::Event> = patches | 596 | let events_with_youngest_created_at: Vec<&nostr::Event> = proposal_events |
| 583 | .iter() | 597 | .iter() |
| 584 | .filter(|p| p.created_at.eq(&youngest_patch.created_at)) | 598 | .filter(|p| p.created_at.eq(&youngest.created_at)) |
| 585 | .collect(); | 599 | .collect(); |
| 586 | 600 | ||
| 587 | let mut res = vec![]; | 601 | let mut res = vec![]; |
| 588 | 602 | ||
| 589 | let mut event_id_to_search = patches_with_youngest_created_at | 603 | let mut event_id_to_search = events_with_youngest_created_at |
| 590 | .clone() | 604 | .clone() |
| 591 | .iter() | 605 | .iter() |
| 592 | .find(|p| { | 606 | .find(|p| { |
| 593 | !patches_with_youngest_created_at.iter().any(|p2| { | 607 | !events_with_youngest_created_at.iter().any(|p2| { |
| 594 | if let Ok(reply_to) = get_event_parent_id(p2) { | 608 | if let Ok(reply_to) = get_event_parent_id(p2) { |
| 595 | reply_to.eq(&p.id.to_string()) | 609 | reply_to.eq(&p.id.to_string()) |
| 596 | } else { | 610 | } else { |
| @@ -598,16 +612,18 @@ pub fn get_most_recent_patch_with_ancestors( | |||
| 598 | } | 612 | } |
| 599 | }) | 613 | }) |
| 600 | }) | 614 | }) |
| 601 | .context("failed to find patches_with_youngest_created_at")? | 615 | .context("failed to find events_with_youngest_created_at")? |
| 602 | .id | 616 | .id |
| 603 | .to_string(); | 617 | .to_string(); |
| 604 | 618 | ||
| 605 | while let Some(event) = patches | 619 | while let Some(event) = proposal_events |
| 606 | .iter() | 620 | .iter() |
| 607 | .find(|e| e.id.to_string().eq(&event_id_to_search)) | 621 | .find(|e| e.id.to_string().eq(&event_id_to_search)) |
| 608 | { | 622 | { |
| 609 | res.push(event.clone()); | 623 | res.push(event.clone()); |
| 610 | if event_is_patch_set_root(event) { | 624 | if [KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE].contains(&event.kind) |
| 625 | || event_is_patch_set_root(event) | ||
| 626 | { | ||
| 611 | break; | 627 | break; |
| 612 | } | 628 | } |
| 613 | event_id_to_search = get_event_parent_id(event).unwrap_or_default(); | 629 | event_id_to_search = get_event_parent_id(event).unwrap_or_default(); |