upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/sub_commands')
-rw-r--r--src/sub_commands/pull.rs29
-rw-r--r--src/sub_commands/push.rs20
2 files changed, 35 insertions, 14 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 @@
1use anyhow::{bail, Context, Result}; 1use anyhow::{bail, Context, Result};
2use nostr_sdk::{Event, PublicKey};
2 3
3use super::{ 4use 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
216pub 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}
diff --git a/src/sub_commands/push.rs b/src/sub_commands/push.rs
index 7a82c7a..15baad9 100644
--- a/src/sub_commands/push.rs
+++ b/src/sub_commands/push.rs
@@ -1,4 +1,5 @@
1use anyhow::{bail, Context, Result}; 1use anyhow::{bail, Context, Result};
2use nostr_sdk::PublicKey;
2 3
3#[cfg(not(test))] 4#[cfg(not(test))]
4use crate::client::Client; 5use crate::client::Client;
@@ -17,10 +18,8 @@ use crate::{
17 get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache, 18 get_most_recent_patch_with_ancestors, get_proposals_and_revisions_from_cache,
18 tag_value, 19 tag_value,
19 }, 20 },
20 send::{ 21 pull::is_event_proposal_root_for_branch,
21 event_is_revision_root, event_to_cover_letter, generate_patch_event, 22 send::{generate_patch_event, identify_ahead_behind, send_events},
22 identify_ahead_behind, send_events,
23 },
24 }, 23 },
25}; 24};
26 25
@@ -62,15 +61,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
62 61
63 let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?; 62 let repo_ref = get_repo_ref_from_cache(git_repo_path, &repo_coordinates).await?;
64 63
64 let logged_in_public_key =
65 if let Ok(Some(npub)) = git_repo.get_git_config_item("nostr.npub", None) {
66 PublicKey::parse(npub).ok()
67 } else {
68 None
69 };
70
65 let proposal_root_event = 71 let proposal_root_event =
66 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates()) 72 get_proposals_and_revisions_from_cache(git_repo_path, repo_ref.coordinates())
67 .await? 73 .await?
68 .iter() 74 .iter()
69 .find(|e| { 75 .find(|e| is_event_proposal_root_for_branch(e, &branch_name, &logged_in_public_key))
70 event_to_cover_letter(e)
71 .is_ok_and(|cl| cl.get_branch_name().is_ok_and(|s| s.eq(&branch_name)))
72 && !event_is_revision_root(e)
73 })
74 .context("cannot find proposal that matches the current branch name")? 76 .context("cannot find proposal that matches the current branch name")?
75 .clone(); 77 .clone();
76 78