diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-13 17:00:00 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-09-13 17:00:00 +0100 |
| commit | 069a4c21c56291455fb9af09b693672889f98a03 (patch) | |
| tree | b4bc6de0114def18abca3380a0491c9ebe230245 /src/bin/ngit/sub_commands/pull.rs | |
| parent | 39bd66ed80d8d0e32e7231f1881b789392f5dacc (diff) | |
refactor: abstract find pr from branch name
so it is done consistantly across ngit and the remote helper
Diffstat (limited to 'src/bin/ngit/sub_commands/pull.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/pull.rs | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/src/bin/ngit/sub_commands/pull.rs b/src/bin/ngit/sub_commands/pull.rs index eba6fc5..9a3d911 100644 --- a/src/bin/ngit/sub_commands/pull.rs +++ b/src/bin/ngit/sub_commands/pull.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use anyhow::{bail, Context, Result}; | 1 | use anyhow::{bail, Context, Result}; |
| 2 | use ngit::git_events::is_event_proposal_root_for_branch; | ||
| 2 | use nostr_sdk::PublicKey; | 3 | use nostr_sdk::PublicKey; |
| 3 | 4 | ||
| 4 | use crate::{ | 5 | use crate::{ |
| @@ -7,10 +8,7 @@ use crate::{ | |||
| 7 | get_proposals_and_revisions_from_cache, get_repo_ref_from_cache, Client, Connect, | 8 | get_proposals_and_revisions_from_cache, get_repo_ref_from_cache, Client, Connect, |
| 8 | }, | 9 | }, |
| 9 | git::{str_to_sha1, Repo, RepoActions}, | 10 | git::{str_to_sha1, Repo, RepoActions}, |
| 10 | git_events::{ | 11 | git_events::{get_commit_id_from_patch, get_most_recent_patch_with_ancestors, tag_value}, |
| 11 | event_is_revision_root, event_to_cover_letter, get_commit_id_from_patch, | ||
| 12 | get_most_recent_patch_with_ancestors, tag_value, | ||
| 13 | }, | ||
| 14 | repo_ref::get_repo_coordinates, | 12 | repo_ref::get_repo_coordinates, |
| 15 | }; | 13 | }; |
| 16 | 14 | ||
| @@ -37,7 +35,7 @@ pub async fn launch() -> Result<()> { | |||
| 37 | 35 | ||
| 38 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; | 36 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 39 | 37 | ||
| 40 | let public_key_if_known = | 38 | let logged_in_public_key = |
| 41 | if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) { | 39 | if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) { |
| 42 | PublicKey::parse(npub).ok() | 40 | PublicKey::parse(npub).ok() |
| 43 | } else { | 41 | } else { |
| @@ -49,15 +47,12 @@ pub async fn launch() -> Result<()> { | |||
| 49 | .await? | 47 | .await? |
| 50 | .iter() | 48 | .iter() |
| 51 | .find(|e| { | 49 | .find(|e| { |
| 52 | event_to_cover_letter(e).is_ok_and(|cl| { | 50 | is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key) |
| 53 | (public_key_if_known.is_some_and(|public_key| e.author().eq(&public_key)) | 51 | .unwrap_or(false) |
| 54 | && (branch_name.eq(&format!("pr/{}", cl.branch_name)) | ||
| 55 | || cl.branch_name.eq(&branch_name))) | ||
| 56 | || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)) | ||
| 57 | }) && !event_is_revision_root(e) | ||
| 58 | }) | 52 | }) |
| 59 | .context("cannot find proposal that matches the current branch name")? | 53 | .context("cannot find proposal that matches the current branch name")? |
| 60 | .clone(); | 54 | .clone(); |
| 55 | |||
| 61 | let commit_events = get_all_proposal_patch_events_from_cache( | 56 | let commit_events = get_all_proposal_patch_events_from_cache( |
| 62 | git_repo_path, | 57 | git_repo_path, |
| 63 | &repo_ref, | 58 | &repo_ref, |