diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-08 15:57:05 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-02-09 06:51:39 +0000 |
| commit | 4b0a35583644e703eb615e0724d33fe93aec932b (patch) | |
| tree | e2b724d7b932c99e4346867a899452b839b57cbc /src/sub_commands/prs/create.rs | |
| parent | 0b9c7521b035e60ad7c458c1e782623e18a5cc21 (diff) | |
feat(prs-create): add `PATCH n/n` to content
format patch as a series in the patch event content unless it is 1/1
and there is no pr (cover letter) event
Diffstat (limited to 'src/sub_commands/prs/create.rs')
| -rw-r--r-- | src/sub_commands/prs/create.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/sub_commands/prs/create.rs b/src/sub_commands/prs/create.rs index 0f7cbda..82824a1 100644 --- a/src/sub_commands/prs/create.rs +++ b/src/sub_commands/prs/create.rs | |||
| @@ -80,7 +80,9 @@ pub async fn launch( | |||
| 80 | 80 | ||
| 81 | let title = match &args.title { | 81 | let title = match &args.title { |
| 82 | Some(t) => t.clone(), | 82 | Some(t) => t.clone(), |
| 83 | None => Interactor::default().input(PromptInputParms::default().with_prompt("title"))?, | 83 | None => Interactor::default() |
| 84 | .input(PromptInputParms::default().with_prompt("title"))? | ||
| 85 | .clone(), | ||
| 84 | }; | 86 | }; |
| 85 | 87 | ||
| 86 | let description = match &args.description { | 88 | let description = match &args.description { |
| @@ -350,7 +352,7 @@ pub fn generate_pr_and_patch_events( | |||
| 350 | let pr_event_id = pr_event.id; | 352 | let pr_event_id = pr_event.id; |
| 351 | 353 | ||
| 352 | let mut events = vec![pr_event]; | 354 | let mut events = vec![pr_event]; |
| 353 | for commit in commits { | 355 | for (i, commit) in commits.iter().enumerate() { |
| 354 | events.push( | 356 | events.push( |
| 355 | generate_patch_event( | 357 | generate_patch_event( |
| 356 | git_repo, | 358 | git_repo, |
| @@ -360,6 +362,11 @@ pub fn generate_pr_and_patch_events( | |||
| 360 | keys, | 362 | keys, |
| 361 | repo_ref, | 363 | repo_ref, |
| 362 | events.last().map(nostr::Event::id), | 364 | events.last().map(nostr::Event::id), |
| 365 | if events.is_empty() { | ||
| 366 | None | ||
| 367 | } else { | ||
| 368 | Some(((i + 1).try_into()?, commits.len().try_into()?)) | ||
| 369 | }, | ||
| 363 | ) | 370 | ) |
| 364 | .context("failed to generate patch event")?, | 371 | .context("failed to generate patch event")?, |
| 365 | ); | 372 | ); |
| @@ -367,6 +374,7 @@ pub fn generate_pr_and_patch_events( | |||
| 367 | Ok(events) | 374 | Ok(events) |
| 368 | } | 375 | } |
| 369 | 376 | ||
| 377 | #[allow(clippy::too_many_arguments)] | ||
| 370 | pub fn generate_patch_event( | 378 | pub fn generate_patch_event( |
| 371 | git_repo: &Repo, | 379 | git_repo: &Repo, |
| 372 | root_commit: &Sha1Hash, | 380 | root_commit: &Sha1Hash, |
| @@ -375,6 +383,7 @@ pub fn generate_patch_event( | |||
| 375 | keys: &nostr::Keys, | 383 | keys: &nostr::Keys, |
| 376 | repo_ref: &RepoRef, | 384 | repo_ref: &RepoRef, |
| 377 | parent_patch_event_id: Option<nostr::EventId>, | 385 | parent_patch_event_id: Option<nostr::EventId>, |
| 386 | series_count: Option<(u64, u64)>, | ||
| 378 | ) -> Result<nostr::Event> { | 387 | ) -> Result<nostr::Event> { |
| 379 | let commit_parent = git_repo | 388 | let commit_parent = git_repo |
| 380 | .get_commit_parent(commit) | 389 | .get_commit_parent(commit) |
| @@ -383,7 +392,7 @@ pub fn generate_patch_event( | |||
| 383 | EventBuilder::new( | 392 | EventBuilder::new( |
| 384 | nostr::event::Kind::Custom(PATCH_KIND), | 393 | nostr::event::Kind::Custom(PATCH_KIND), |
| 385 | git_repo | 394 | git_repo |
| 386 | .make_patch_from_commit(commit) | 395 | .make_patch_from_commit(commit,&series_count) |
| 387 | .context(format!("cannot make patch for commit {commit}"))?, | 396 | .context(format!("cannot make patch for commit {commit}"))?, |
| 388 | [ | 397 | [ |
| 389 | vec![ | 398 | vec![ |