diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-13 14:52:24 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-13 15:55:54 +0000 |
| commit | cf319efc6dcdc6c54564cb84e13218edbf3643fa (patch) | |
| tree | ccccf807fac6c2ab242b2d6bb322c679ae5b94f7 /src/sub_commands/pull.rs | |
| parent | 3112576195aef212622d27ad9164336796c1953e (diff) | |
feat!: nip34 make pr event optional
use first patch as thread root if pr event isn't present.
begin renaming pr event to cover letter.
fix patch ordering upon creation. patches were in youngest first
order which caused:
- `PATCH n/t`to be in reverse order
- the youngest patch was the marked root
- oldest patch replied to the youngest
fix finding most recent patch event. when a patch in a set is the
most recent it will share a created_at with other patches.
previously the first patch recieved from relay in the set would be
used. now it finds the first patch with that created_at which isn't
also a parent of another patch with the same created_at.
Diffstat (limited to 'src/sub_commands/pull.rs')
| -rw-r--r-- | src/sub_commands/pull.rs | 62 |
1 files changed, 6 insertions, 56 deletions
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index f3ae81f..2b20d3d 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs | |||
| @@ -8,10 +8,8 @@ use crate::{ | |||
| 8 | client::Connect, | 8 | client::Connect, |
| 9 | git::{Repo, RepoActions}, | 9 | git::{Repo, RepoActions}, |
| 10 | repo_ref, | 10 | repo_ref, |
| 11 | repo_ref::REPO_REF_KIND, | 11 | sub_commands::{ |
| 12 | sub_commands::prs::{ | 12 | prs::list::get_most_recent_patch_with_ancestors, push::fetch_pr_and_most_recent_patch_chain, |
| 13 | create::{PATCH_KIND, PR_KIND}, | ||
| 14 | list::{get_most_recent_patch_with_ancestors, tag_value}, | ||
| 15 | }, | 13 | }, |
| 16 | }; | 14 | }; |
| 17 | 15 | ||
| @@ -46,63 +44,15 @@ pub async fn launch() -> Result<()> { | |||
| 46 | ) | 44 | ) |
| 47 | .await?; | 45 | .await?; |
| 48 | 46 | ||
| 49 | println!("finding PR event..."); | 47 | let (_pr_event, commit_events) = |
| 50 | 48 | fetch_pr_and_most_recent_patch_chain(&client, &repo_ref, &root_commit, &branch_name) | |
| 51 | let pr_event: nostr::Event = client | 49 | .await?; |
| 52 | .get_events( | ||
| 53 | repo_ref.relays.clone(), | ||
| 54 | vec![ | ||
| 55 | nostr::Filter::default() | ||
| 56 | .kind(nostr::Kind::Custom(PR_KIND)) | ||
| 57 | .identifiers( | ||
| 58 | repo_ref | ||
| 59 | .maintainers | ||
| 60 | .iter() | ||
| 61 | .map(|m| format!("{REPO_REF_KIND}:{m}:{}", repo_ref.identifier)), | ||
| 62 | ), | ||
| 63 | ], | ||
| 64 | ) | ||
| 65 | .await? | ||
| 66 | .iter() | ||
| 67 | .find(|e| { | ||
| 68 | e.kind.as_u64() == PR_KIND | ||
| 69 | && e.tags | ||
| 70 | .iter() | ||
| 71 | .any(|t| t.as_vec().len() > 1 && t.as_vec()[1].eq(&format!("{root_commit}"))) | ||
| 72 | && tag_value(e, "branch-name") | ||
| 73 | .unwrap_or_default() | ||
| 74 | .eq(&branch_name) | ||
| 75 | }) | ||
| 76 | .context("cannot find a PR event associated with the checked out branch name")? | ||
| 77 | .to_owned(); | ||
| 78 | |||
| 79 | println!("found PR event. finding commits..."); | ||
| 80 | |||
| 81 | let commits_events: Vec<nostr::Event> = client | ||
| 82 | .get_events( | ||
| 83 | repo_ref.relays.clone(), | ||
| 84 | vec![ | ||
| 85 | nostr::Filter::default() | ||
| 86 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 87 | .event(pr_event.id), | ||
| 88 | ], | ||
| 89 | ) | ||
| 90 | .await? | ||
| 91 | .iter() | ||
| 92 | .filter(|e| { | ||
| 93 | e.kind.as_u64() == PATCH_KIND | ||
| 94 | && e.tags | ||
| 95 | .iter() | ||
| 96 | .any(|t| t.as_vec().len() > 2 && t.as_vec()[1].eq(&pr_event.id.to_string())) | ||
| 97 | }) | ||
| 98 | .map(std::borrow::ToOwned::to_owned) | ||
| 99 | .collect(); | ||
| 100 | 50 | ||
| 101 | if git_repo.has_outstanding_changes()? { | 51 | if git_repo.has_outstanding_changes()? { |
| 102 | bail!("cannot pull changes when repository is not clean. discard changes and try again."); | 52 | bail!("cannot pull changes when repository is not clean. discard changes and try again."); |
| 103 | } | 53 | } |
| 104 | 54 | ||
| 105 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commits_events) | 55 | let most_recent_pr_patch_chain = get_most_recent_patch_with_ancestors(commit_events) |
| 106 | .context("cannot get most recent patch for PR")?; | 56 | .context("cannot get most recent patch for PR")?; |
| 107 | 57 | ||
| 108 | let applied = git_repo | 58 | let applied = git_repo |