diff options
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/git_events.rs | 10 | ||||
| -rw-r--r-- | src/lib/push.rs | 3 | ||||
| -rw-r--r-- | src/lib/utils.rs | 36 |
3 files changed, 46 insertions, 3 deletions
diff --git a/src/lib/git_events.rs b/src/lib/git_events.rs index 79f5772..bbfcbea 100644 --- a/src/lib/git_events.rs +++ b/src/lib/git_events.rs | |||
| @@ -376,11 +376,13 @@ pub fn event_tag_from_nip19_or_hex( | |||
| 376 | } | 376 | } |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | #[allow(clippy::too_many_arguments)] | ||
| 379 | pub fn generate_unsigned_pr_or_update_event( | 380 | pub fn generate_unsigned_pr_or_update_event( |
| 380 | git_repo: &Repo, | 381 | git_repo: &Repo, |
| 381 | repo_ref: &RepoRef, | 382 | repo_ref: &RepoRef, |
| 382 | signing_public_key: &PublicKey, | 383 | signing_public_key: &PublicKey, |
| 383 | root_proposal: Option<&Event>, | 384 | root_proposal: Option<&Event>, |
| 385 | title_description_overide: &Option<(String, String)>, | ||
| 384 | commit: &Sha1Hash, | 386 | commit: &Sha1Hash, |
| 385 | clone_url_hint: &[&str], | 387 | clone_url_hint: &[&str], |
| 386 | mentions: &[nostr::Tag], | 388 | mentions: &[nostr::Tag], |
| @@ -395,13 +397,17 @@ pub fn generate_unsigned_pr_or_update_event( | |||
| 395 | None | 397 | None |
| 396 | }; | 398 | }; |
| 397 | 399 | ||
| 398 | let title = if let Some(cl) = &root_patch_cover_letter { | 400 | let title = if let Some((title, _)) = &title_description_overide { |
| 401 | title.clone() | ||
| 402 | } else if let Some(cl) = &root_patch_cover_letter { | ||
| 399 | cl.title.clone() | 403 | cl.title.clone() |
| 400 | } else { | 404 | } else { |
| 401 | git_repo.get_commit_message_summary(commit)? | 405 | git_repo.get_commit_message_summary(commit)? |
| 402 | }; | 406 | }; |
| 403 | 407 | ||
| 404 | let description = if let Some(cl) = &root_patch_cover_letter { | 408 | let description = if let Some((_, description)) = &title_description_overide { |
| 409 | description.clone() | ||
| 410 | } else if let Some(cl) = &root_patch_cover_letter { | ||
| 405 | cl.description.clone() | 411 | cl.description.clone() |
| 406 | } else { | 412 | } else { |
| 407 | let mut description = git_repo.get_commit_message(commit)?.trim().to_string(); | 413 | let mut description = git_repo.get_commit_message(commit)?.trim().to_string(); |
diff --git a/src/lib/push.rs b/src/lib/push.rs index 1c09555..bcd368b 100644 --- a/src/lib/push.rs +++ b/src/lib/push.rs | |||
| @@ -321,12 +321,14 @@ impl<'a> PushReporter<'a> { | |||
| 321 | } | 321 | } |
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | #[allow(clippy::too_many_arguments)] | ||
| 324 | pub async fn push_refs_and_generate_pr_or_pr_update_event( | 325 | pub async fn push_refs_and_generate_pr_or_pr_update_event( |
| 325 | git_repo: &Repo, | 326 | git_repo: &Repo, |
| 326 | repo_ref: &RepoRef, | 327 | repo_ref: &RepoRef, |
| 327 | tip: &Sha1Hash, | 328 | tip: &Sha1Hash, |
| 328 | user_ref: &UserRef, | 329 | user_ref: &UserRef, |
| 329 | root_proposal: Option<&Event>, | 330 | root_proposal: Option<&Event>, |
| 331 | title_description_overide: &Option<(String, String)>, | ||
| 330 | signer: &Arc<dyn NostrSigner>, | 332 | signer: &Arc<dyn NostrSigner>, |
| 331 | term: &Term, | 333 | term: &Term, |
| 332 | ) -> Result<Vec<Event>> { | 334 | ) -> Result<Vec<Event>> { |
| @@ -348,6 +350,7 @@ pub async fn push_refs_and_generate_pr_or_pr_update_event( | |||
| 348 | repo_ref, | 350 | repo_ref, |
| 349 | &user_ref.public_key, | 351 | &user_ref.public_key, |
| 350 | root_proposal, | 352 | root_proposal, |
| 353 | title_description_overide, | ||
| 351 | tip, | 354 | tip, |
| 352 | &[clone_url], | 355 | &[clone_url], |
| 353 | &[], | 356 | &[], |
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>)>, |