diff options
Diffstat (limited to 'src/sub_commands/pull.rs')
| -rw-r--r-- | src/sub_commands/pull.rs | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/sub_commands/pull.rs b/src/sub_commands/pull.rs index e33a744..2547be5 100644 --- a/src/sub_commands/pull.rs +++ b/src/sub_commands/pull.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use anyhow::{bail, Context, Result}; | 1 | use anyhow::{bail, Context, Result}; |
| 2 | use nostr_sdk::{Event, PublicKey}; | ||
| 2 | 3 | ||
| 3 | use super::{ | 4 | use super::{ |
| 4 | list::{ | 5 | list::{ |
| @@ -45,17 +46,21 @@ pub async fn launch() -> Result<()> { | |||
| 45 | 46 | ||
| 46 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; | 47 | let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; |
| 47 | 48 | ||
| 49 | let logged_in_public_key = | ||
| 50 | if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) { | ||
| 51 | PublicKey::parse(npub).ok() | ||
| 52 | } else { | ||
| 53 | None | ||
| 54 | }; | ||
| 55 | |||
| 48 | let proposal_root_event = | 56 | let proposal_root_event = |
| 49 | get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) | 57 | get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) |
| 50 | .await? | 58 | .await? |
| 51 | .iter() | 59 | .iter() |
| 52 | .find(|e| { | 60 | .find(|e| is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key)) |
| 53 | event_to_cover_letter(e) | ||
| 54 | .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))) | ||
| 55 | && !event_is_revision_root(e) | ||
| 56 | }) | ||
| 57 | .context("cannot find proposal that matches the current branch name")? | 61 | .context("cannot find proposal that matches the current branch name")? |
| 58 | .clone(); | 62 | .clone(); |
| 63 | |||
| 59 | let commit_events = get_all_proposal_patch_events_from_cache( | 64 | let commit_events = get_all_proposal_patch_events_from_cache( |
| 60 | git_repo_path, | 65 | git_repo_path, |
| 61 | &repo_ref, | 66 | &repo_ref, |
| @@ -207,3 +212,17 @@ fn check_clean(git_repo: &Repo) -> Result<()> { | |||
| 207 | } | 212 | } |
| 208 | Ok(()) | 213 | Ok(()) |
| 209 | } | 214 | } |
| 215 | |||
| 216 | pub fn is_event_proposal_root_for_branch( | ||
| 217 | e: &Event, | ||
| 218 | branch_name_or_refstr: &str, | ||
| 219 | logged_in_user: &Option<PublicKey>, | ||
| 220 | ) -> bool { | ||
| 221 | let branch_name = branch_name_or_refstr.replace("refs/heads/", ""); | ||
| 222 | event_to_cover_letter(e).is_ok_and(|cl| { | ||
| 223 | (logged_in_user.is_some_and(|public_key| e.author().eq(&public_key)) | ||
| 224 | && (branch_name.eq(&format!("pr/{}", cl.branch_name)) | ||
| 225 | || cl.branch_name.eq(&branch_name))) | ||
| 226 | || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)) | ||
| 227 | }) && !event_is_revision_root(e) | ||
| 228 | } | ||