this repo has no description

Show commit messages in template

+41 -4
+41 -4
src/main.rs
··· 489 489 branch: &str, 490 490 target: &str, 491 491 ) -> color_eyre::Result<Option<(String, String)>> { 492 + use std::fmt::Write; 493 + 492 494 let body = std::fs::read_to_string(".github/pull_request_template.md") 493 495 .unwrap_or_else(|_| "...and description here".to_owned()); 494 496 ··· 497 499 ["diff", "--git", "-r", &format!("{target}..{branch}")], 498 500 )?; 499 501 502 + let count = command( 503 + "jj", 504 + ["log", "--count", "-r", &format!("{target}..{branch}")], 505 + )? 506 + .trim() 507 + .parse::<i32>()?; 508 + 500 509 let ignored_marker = "Everything below this line will be ignored"; 501 510 502 - if let Some(text) = Editor::new().extension(".jjdescription").edit(&format!( 503 - "Enter PR title...\n\n{body}\n\ 504 - JJ: {ignored_marker}\n\n{diff}" 505 - ))? { 511 + let commit_descriptions = command( 512 + "jj", 513 + [ 514 + "log", 515 + "--no-graph", 516 + "-r", 517 + &format!("{target}..{branch}"), 518 + "-T", 519 + "description ++ \"\n\"", 520 + ], 521 + )?; 522 + let commit_descriptions = commit_descriptions.trim().to_owned(); 523 + 524 + let mut template = if count == 1 { 525 + commit_descriptions.clone() 526 + } else { 527 + format!("Enter PR title...\n\n{body}") 528 + }; 529 + writeln!(&mut template)?; 530 + writeln!(&mut template)?; 531 + writeln!(&mut template, "JJ: {ignored_marker}")?; 532 + if count != 1 { 533 + writeln!(&mut template)?; 534 + write!(&mut template, "{commit_descriptions}")?; 535 + } 536 + if !diff.trim().is_empty() { 537 + writeln!(&mut template)?; 538 + writeln!(&mut template)?; 539 + writeln!(&mut template, "{diff}")?; 540 + } 541 + 542 + if let Some(text) = Editor::new().extension(".jjdescription").edit(&template)? { 506 543 if text.trim().is_empty() { 507 544 bail!("empty PR title and description"); 508 545 }