upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/utils.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-08-04 11:50:39 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2025-08-05 09:23:01 +0100
commitf48677bad3f3dabb80992806e0e4c8ad4d45c716 (patch)
tree9d63debff0b602a15df56008cc739c087fbe8b26 /src/lib/utils.rs
parentf76fe63da5f2c2f85215e86c8ecc63eda7c93902 (diff)
feat(send): support PR and PR update events
send as a PR if the commit would make patches that are too big for nostr events. send as a PR update if the proposal is PR. send as a PR, revising a patch root, if patches would be too big. in tests `get_pretend_proposal_root_event` has to be a actual proposal with a tip, rather than just a cover letter, so we have replaced it.
Diffstat (limited to 'src/lib/utils.rs')
-rw-r--r--src/lib/utils.rs36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/lib/utils.rs b/src/lib/utils.rs
index 431757f..431a14f 100644
--- a/src/lib/utils.rs
+++ b/src/lib/utils.rs
@@ -3,11 +3,13 @@ use std::{
3 collections::HashMap, 3 collections::HashMap,
4 fmt, 4 fmt,
5 io::{self, Stdin}, 5 io::{self, Stdin},
6 path::Path,
6 str::FromStr, 7 str::FromStr,
7}; 8};
8 9
9use anyhow::{Context, Result, bail}; 10use anyhow::{Context, Result, bail};
10use git2::Repository; 11use git2::Repository;
12use nostr::nips::nip19::ToBech32;
11use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; 13use nostr_sdk::{Event, EventId, Kind, PublicKey, Url};
12 14
13use crate::{ 15use crate::{
@@ -20,7 +22,8 @@ use crate::{
20 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, 22 nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol},
21 }, 23 },
22 git_events::{ 24 git_events::{
23 event_is_revision_root, get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status, 25 KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE, event_is_revision_root,
26 get_pr_tip_event_or_most_recent_patch_with_ancestors, get_status,
24 is_event_proposal_root_for_branch, status_kinds, 27 is_event_proposal_root_for_branch, status_kinds,
25 }, 28 },
26 repo_ref::RepoRef, 29 repo_ref::RepoRef,
@@ -187,6 +190,37 @@ pub async fn get_all_proposals(
187 Ok(all_proposals) 190 Ok(all_proposals)
188} 191}
189 192
193pub async fn proposal_tip_is_pr_or_pr_update(
194 git_repo_path: &Path,
195 repo_ref: &RepoRef,
196 proposal_id: &EventId,
197) -> Result<bool> {
198 let commits_events =
199 get_all_proposal_patch_pr_pr_update_events_from_cache(git_repo_path, repo_ref, proposal_id)
200 .await
201 .context(format!(
202 "cannot get existing proposal events for {}",
203 proposal_id.to_bech32()?
204 ))?;
205 let most_recent_proposal_patch_chain = get_pr_tip_event_or_most_recent_patch_with_ancestors(
206 commits_events.clone(),
207 )
208 .context(format!(
209 "cannot find tip from proposal events for {}",
210 proposal_id.to_bech32()?,
211 ))?;
212
213 Ok([KIND_PULL_REQUEST, KIND_PULL_REQUEST_UPDATE].contains(
214 &most_recent_proposal_patch_chain
215 .first()
216 .context(format!(
217 "cannot find any proposal events for {}",
218 proposal_id.to_bech32()?
219 ))?
220 .kind,
221 ))
222}
223
190pub fn find_proposal_and_patches_by_branch_name<'a>( 224pub fn find_proposal_and_patches_by_branch_name<'a>(
191 refstr: &'a str, 225 refstr: &'a str,
192 proposals: &'a HashMap<EventId, (Event, Vec<Event>)>, 226 proposals: &'a HashMap<EventId, (Event, Vec<Event>)>,