diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-20 09:59:14 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-12-20 10:17:27 +0000 |
| commit | 316f858f223162408cfd52183ef7645828c2f480 (patch) | |
| tree | 4f275320ad776ed4fcc85a1d75b2ac2c46c63609 /src/bin/git_remote_nostr | |
| parent | 8cc4a21061433c9a29e36c4f33e4d84bea1defee (diff) | |
refactor: branch_name handling
improve clarity by renaming variables and methods
defend against `branch-name` tag with an unsafe name
Diffstat (limited to 'src/bin/git_remote_nostr')
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 4 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 6 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 4 |
3 files changed, 8 insertions, 6 deletions
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( | |||
| 149 | let current_user = get_curent_user(git_repo)?; | 149 | let current_user = get_curent_user(git_repo)?; |
| 150 | for (_, (proposal, patches)) in open_proposals { | 150 | for (_, (proposal, patches)) in open_proposals { |
| 151 | if let Ok(cl) = event_to_cover_letter(&proposal) { | 151 | if let Ok(cl) = event_to_cover_letter(&proposal) { |
| 152 | if let Ok(mut branch_name) = cl.get_branch_name() { | 152 | if let Ok(mut branch_name) = cl.get_branch_name_with_pr_prefix_and_shorthand_id() { |
| 153 | branch_name = if let Some(public_key) = current_user { | 153 | branch_name = if let Some(public_key) = current_user { |
| 154 | if proposal.pubkey.eq(&public_key) { | 154 | if proposal.pubkey.eq(&public_key) { |
| 155 | format!("pr/{}", cl.branch_name) | 155 | format!("pr/{}", cl.branch_name_without_id_or_prefix) |
| 156 | } else { | 156 | } else { |
| 157 | branch_name | 157 | branch_name |
| 158 | } | 158 | } |
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( | |||
| 1184 | term.write_line( | 1184 | term.write_line( |
| 1185 | format!( | 1185 | format!( |
| 1186 | "applied commits from proposal: create nostr proposal status event for {}", | 1186 | "applied commits from proposal: create nostr proposal status event for {}", |
| 1187 | event_to_cover_letter(&proposal)?.get_branch_name()?, | 1187 | event_to_cover_letter(&proposal)? |
| 1188 | .get_branch_name_with_pr_prefix_and_shorthand_id()?, | ||
| 1188 | ) | 1189 | ) |
| 1189 | .as_str(), | 1190 | .as_str(), |
| 1190 | )?; | 1191 | )?; |
| @@ -1192,7 +1193,8 @@ async fn create_merge_events( | |||
| 1192 | term.write_line( | 1193 | term.write_line( |
| 1193 | format!( | 1194 | format!( |
| 1194 | "fast-forward merge: create nostr proposal status event for {}", | 1195 | "fast-forward merge: create nostr proposal status event for {}", |
| 1195 | event_to_cover_letter(&proposal)?.get_branch_name()?, | 1196 | event_to_cover_letter(&proposal)? |
| 1197 | .get_branch_name_with_pr_prefix_and_shorthand_id()?, | ||
| 1196 | ) | 1198 | ) |
| 1197 | .as_str(), | 1199 | .as_str(), |
| 1198 | )?; | 1200 | )?; |
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( | |||
| 184 | 184 | ||
| 185 | pub fn find_proposal_and_patches_by_branch_name<'a>( | 185 | pub fn find_proposal_and_patches_by_branch_name<'a>( |
| 186 | refstr: &'a str, | 186 | refstr: &'a str, |
| 187 | open_proposals: &'a HashMap<EventId, (Event, Vec<Event>)>, | 187 | proposals: &'a HashMap<EventId, (Event, Vec<Event>)>, |
| 188 | current_user: Option<&PublicKey>, | 188 | current_user: Option<&PublicKey>, |
| 189 | ) -> Option<(&'a EventId, &'a (Event, Vec<Event>))> { | 189 | ) -> Option<(&'a EventId, &'a (Event, Vec<Event>))> { |
| 190 | open_proposals.iter().find(|(_, (proposal, _))| { | 190 | proposals.iter().find(|(_, (proposal, _))| { |
| 191 | is_event_proposal_root_for_branch(proposal, refstr, current_user).unwrap_or(false) | 191 | is_event_proposal_root_for_branch(proposal, refstr, current_user).unwrap_or(false) |
| 192 | }) | 192 | }) |
| 193 | } | 193 | } |