From 316f858f223162408cfd52183ef7645828c2f480 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 20 Dec 2024 09:59:14 +0000 Subject: refactor: branch_name handling improve clarity by renaming variables and methods defend against `branch-name` tag with an unsafe name --- src/bin/git_remote_nostr/list.rs | 4 ++-- src/bin/git_remote_nostr/push.rs | 6 ++++-- src/bin/git_remote_nostr/utils.rs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'src/bin/git_remote_nostr') diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 07c6f59..f361272 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs @@ -149,10 +149,10 @@ async fn get_open_proposals_state( let current_user = get_curent_user(git_repo)?; for (_, (proposal, patches)) in open_proposals { if let Ok(cl) = event_to_cover_letter(&proposal) { - if let Ok(mut branch_name) = cl.get_branch_name() { + if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() { branch_name = if let Some(public_key) = current_user { if proposal.pubkey.eq(&public_key) { - format!("pr/{}", cl.branch_name) + format!("pr/{}", cl.branch_name_without_id_or_prefix) } else { branch_name } diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 05c8fc2..922808c 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs @@ -1184,7 +1184,8 @@ async fn create_merge_events( term.write_line( format!( "applied commits from proposal: create nostr proposal status event for {}", - event_to_cover_letter(&proposal)?.get_branch_name()?, + event_to_cover_letter(&proposal)? + .get_branch_name_with_pr_prefix_and_shorthand_id()?, ) .as_str(), )?; @@ -1192,7 +1193,8 @@ async fn create_merge_events( term.write_line( format!( "fast-forward merge: create nostr proposal status event for {}", - event_to_cover_letter(&proposal)?.get_branch_name()?, + event_to_cover_letter(&proposal)? + .get_branch_name_with_pr_prefix_and_shorthand_id()?, ) .as_str(), )?; diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 15ebb10..316fedb 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs @@ -184,10 +184,10 @@ pub async fn get_all_proposals( pub fn find_proposal_and_patches_by_branch_name<'a>( refstr: &'a str, - open_proposals: &'a HashMap)>, + proposals: &'a HashMap)>, current_user: Option<&PublicKey>, ) -> Option<(&'a EventId, &'a (Event, Vec))> { - open_proposals.iter().find(|(_, (proposal, _))| { + proposals.iter().find(|(_, (proposal, _))| { is_event_proposal_root_for_branch(proposal, refstr, current_user).unwrap_or(false) }) } -- cgit v1.2.3