diff options
Diffstat (limited to 'src/lib/utils.rs')
| -rw-r--r-- | src/lib/utils.rs | 36 |
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 | ||
| 9 | use anyhow::{Context, Result, bail}; | 10 | use anyhow::{Context, Result, bail}; |
| 10 | use git2::Repository; | 11 | use git2::Repository; |
| 12 | use nostr::nips::nip19::ToBech32; | ||
| 11 | use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; | 13 | use nostr_sdk::{Event, EventId, Kind, PublicKey, Url}; |
| 12 | 14 | ||
| 13 | use crate::{ | 15 | use 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 | ||
| 193 | pub 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 | |||
| 190 | pub fn find_proposal_and_patches_by_branch_name<'a>( | 224 | pub 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>)>, |