upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands/push.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-13 17:00:00 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-13 17:00:00 +0100
commit069a4c21c56291455fb9af09b693672889f98a03 (patch)
treeb4bc6de0114def18abca3380a0491c9ebe230245 /src/bin/ngit/sub_commands/push.rs
parent39bd66ed80d8d0e32e7231f1881b789392f5dacc (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/push.rs')
-rw-r--r--src/bin/ngit/sub_commands/push.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/bin/ngit/sub_commands/push.rs b/src/bin/ngit/sub_commands/push.rs
index 7cdc655..66edfb4 100644
--- a/src/bin/ngit/sub_commands/push.rs
+++ b/src/bin/ngit/sub_commands/push.rs
@@ -1,5 +1,8 @@
1use anyhow::{bail, Context, Result}; 1use anyhow::{bail, Context, Result};
2use ngit::{client::send_events, git_events::tag_value}; 2use ngit::{
3 client::send_events,
4 git_events::{is_event_proposal_root_for_branch, tag_value},
5};
3use nostr_sdk::PublicKey; 6use nostr_sdk::PublicKey;
4 7
5use crate::{ 8use crate::{
@@ -10,8 +13,7 @@ use crate::{
10 }, 13 },
11 git::{identify_ahead_behind, str_to_sha1, Repo, RepoActions}, 14 git::{identify_ahead_behind, str_to_sha1, Repo, RepoActions},
12 git_events::{ 15 git_events::{
13 event_is_revision_root, event_to_cover_letter, generate_patch_event, 16 generate_patch_event, get_commit_id_from_patch, get_most_recent_patch_with_ancestors,
14 get_commit_id_from_patch, get_most_recent_patch_with_ancestors,
15 }, 17 },
16 login, 18 login,
17 repo_ref::get_repo_coordinates, 19 repo_ref::get_repo_coordinates,
@@ -53,7 +55,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
53 55
54 let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; 56 let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?;
55 57
56 let public_key_if_known = 58 let logged_in_public_key =
57 if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) { 59 if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) {
58 PublicKey::parse(npub).ok() 60 PublicKey::parse(npub).ok()
59 } else { 61 } else {
@@ -65,12 +67,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
65 .await? 67 .await?
66 .iter() 68 .iter()
67 .find(|e| { 69 .find(|e| {
68 event_to_cover_letter(e).is_ok_and(|cl| { 70 is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key)
69 (public_key_if_known.is_some_and(|public_key| e.author().eq(&public_key)) 71 .unwrap_or(false)
70 && (branch_name.eq(&format!("pr/{}", cl.branch_name))
71 || cl.branch_name.eq(&branch_name)))
72 || cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name))
73 }) && !event_is_revision_root(e)
74 }) 72 })
75 .context("cannot find proposal that matches the current branch name")? 73 .context("cannot find proposal that matches the current branch name")?
76 .clone(); 74 .clone();