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/push.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/push.rs')
| -rw-r--r-- | src/sub_commands/push.rs | 64 |
1 files changed, 19 insertions, 45 deletions
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs index 61d5d46..eb42699 100644 --- a/src/sub_commands/push.rs +++ b/src/sub_commands/push.rs | |||
| @@ -9,10 +9,13 @@ use crate::{ | |||
| 9 | client::Connect, | 9 | client::Connect, |
| 10 | git::{str_to_sha1, Repo, RepoActions}, | 10 | git::{str_to_sha1, Repo, RepoActions}, |
| 11 | login, | 11 | login, |
| 12 | repo_ref::{self, RepoRef, REPO_REF_KIND}, | 12 | repo_ref::{self, RepoRef}, |
| 13 | sub_commands::prs::{ | 13 | sub_commands::prs::{ |
| 14 | create::{generate_patch_event, send_events, PATCH_KIND, PR_KIND}, | 14 | create::{event_to_cover_letter, generate_patch_event, send_events}, |
| 15 | list::{get_most_recent_patch_with_ancestors, tag_value}, | 15 | list::{ |
| 16 | find_commits_for_pr_event, find_pr_events, get_most_recent_patch_with_ancestors, | ||
| 17 | tag_value, | ||
| 18 | }, | ||
| 16 | }, | 19 | }, |
| 17 | Cli, | 20 | Cli, |
| 18 | }; | 21 | }; |
| @@ -111,6 +114,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 111 | &repo_ref, | 114 | &repo_ref, |
| 112 | patch_events.last().map(nostr::Event::id), | 115 | patch_events.last().map(nostr::Event::id), |
| 113 | None, | 116 | None, |
| 117 | None, | ||
| 114 | ) | 118 | ) |
| 115 | .context("cannot make patch event from commit")?, | 119 | .context("cannot make patch event from commit")?, |
| 116 | ); | 120 | ); |
| @@ -131,7 +135,7 @@ pub async fn launch(cli_args: &Cli) -> Result<()> { | |||
| 131 | Ok(()) | 135 | Ok(()) |
| 132 | } | 136 | } |
| 133 | 137 | ||
| 134 | async fn fetch_pr_and_most_recent_patch_chain( | 138 | pub async fn fetch_pr_and_most_recent_patch_chain( |
| 135 | #[cfg(test)] client: &crate::client::MockConnect, | 139 | #[cfg(test)] client: &crate::client::MockConnect, |
| 136 | #[cfg(not(test))] client: &Client, | 140 | #[cfg(not(test))] client: &Client, |
| 137 | repo_ref: &RepoRef, | 141 | repo_ref: &RepoRef, |
| @@ -140,54 +144,24 @@ async fn fetch_pr_and_most_recent_patch_chain( | |||
| 140 | ) -> Result<(nostr::Event, Vec<nostr::Event>)> { | 144 | ) -> Result<(nostr::Event, Vec<nostr::Event>)> { |
| 141 | println!("finding PR event..."); | 145 | println!("finding PR event..."); |
| 142 | 146 | ||
| 143 | let pr_event: nostr::Event = client | 147 | let pr_events: Vec<nostr::Event> = find_pr_events(client, repo_ref, &root_commit.to_string()) |
| 144 | .get_events( | 148 | .await |
| 145 | repo_ref.relays.clone(), | 149 | .context("cannot get pr events for repo")?; |
| 146 | vec![ | 150 | |
| 147 | nostr::Filter::default() | 151 | let pr_event: nostr::Event = pr_events |
| 148 | .kind(nostr::Kind::Custom(PR_KIND)) | ||
| 149 | .identifiers( | ||
| 150 | repo_ref | ||
| 151 | .maintainers | ||
| 152 | .iter() | ||
| 153 | .map(|m| format!("{REPO_REF_KIND}:{m}:{}", repo_ref.identifier)), | ||
| 154 | ), | ||
| 155 | ], | ||
| 156 | ) | ||
| 157 | .await? | ||
| 158 | .iter() | 152 | .iter() |
| 159 | .find(|e| { | 153 | .find(|e| { |
| 160 | e.kind.as_u64() == PR_KIND | 154 | event_to_cover_letter(e).is_ok_and(|cl| cl.branch_name.eq(branch_name)) |
| 161 | && e.tags | 155 | // TODO remove the dependancy on same branch name and replace with |
| 162 | .iter() | 156 | // references stored in .git/ngit |
| 163 | .any(|t| t.as_vec().len() > 1 && t.as_vec()[1].eq(&format!("{root_commit}"))) | ||
| 164 | && tag_value(e, "branch-name") | ||
| 165 | .unwrap_or_default() | ||
| 166 | .eq(branch_name) | ||
| 167 | }) | 157 | }) |
| 168 | .context("cannot find a PR event associated with the checked out branch name")? | 158 | .context("cannot find a PR event associated with the checked out branch name")? |
| 169 | .to_owned(); | 159 | .to_owned(); |
| 170 | 160 | ||
| 171 | println!("found PR event. finding commits..."); | 161 | println!("found PR event. finding commits..."); |
| 172 | 162 | ||
| 173 | let commits_events: Vec<nostr::Event> = client | 163 | let commits_events: Vec<nostr::Event> = |
| 174 | .get_events( | 164 | find_commits_for_pr_event(client, &pr_event, repo_ref).await?; |
| 175 | repo_ref.relays.clone(), | 165 | |
| 176 | vec![ | ||
| 177 | nostr::Filter::default() | ||
| 178 | .kind(nostr::Kind::Custom(PATCH_KIND)) | ||
| 179 | .event(pr_event.id), | ||
| 180 | ], | ||
| 181 | ) | ||
| 182 | .await? | ||
| 183 | .iter() | ||
| 184 | .filter(|e| { | ||
| 185 | e.kind.as_u64() == PATCH_KIND | ||
| 186 | && e.tags | ||
| 187 | .iter() | ||
| 188 | .any(|t| t.as_vec().len() > 2 && t.as_vec()[1].eq(&pr_event.id.to_string())) | ||
| 189 | }) | ||
| 190 | .map(std::borrow::ToOwned::to_owned) | ||
| 191 | .collect(); | ||
| 192 | Ok((pr_event, commits_events)) | 166 | Ok((pr_event, commits_events)) |
| 193 | } | 167 | } |