diff --git a/Cargo.toml b/Cargo.toml index b685dd3..2330239 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,5 @@ tempfile = "3.3" open = "3.0" colored = "2.0" futures = "0.3" -dialoguer = "0.10.4" \ No newline at end of file +dialoguer = "0.10.4" +chrono = "0.4" \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b3ae97f..148be36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use colored::*; use futures::future::join_all; use dialoguer::Input; use serde::{Serialize, Deserialize}; +use chrono::Local; fn run_git_command(repo_path: &str, git_command: &str, index: Option) -> Result { let mut command = Command::new("sh"); @@ -139,20 +140,36 @@ async fn main() { let mut commit_state = load_commit_state(&data_dir); + // Save summaries in date-organized folders: data/summaries/YYYY-MM-DD/ + let now = Local::now(); + let date_str = now.format("%Y-%m-%d").to_string(); + let time_str = now.format("%H%M%S").to_string(); + let summaries_dir = current_dir.join("data").join("summaries").join(&date_str); + create_dir_all(&summaries_dir).expect("failed to create summaries directory"); + + let dated_filename = format!("summary-{}.md", time_str); + let dated_file_path = summaries_dir.join(&dated_filename); + + // Also write to the root file for backward compatibility let file_path = current_dir.join("git_commit_summaries.md"); let file_path_str = file_path.to_str().expect("Failed to convert file path to string"); let mut file = File::create(&file_path).expect("Failed to create file"); - - writeln!(file, "# Git Commit Summaries\n").expect("Failed to write to file"); - - writeln!(file, "-----------------------------------------------------------------------").expect("Failed to write to file"); - writeln!(file, "-----------------------------------------------------------------------").expect("Failed to write to file"); - writeln!(file, " ").expect("Failed to write to file"); - writeln!(file, "PRESS CMD+SHIFT+V TO VIEW IN MARKDOWN").expect("Failed to write to file"); - writeln!(file, " ").expect("Failed to write to file"); - writeln!(file, "_______________________________________________________________________").expect("Failed to write to file"); - writeln!(file, "-----------------------------------------------------------------------").expect("Failed to write to file"); - writeln!(file, "Total number of commits: {}\n", commit_hashes.len()).expect("Failed to write to file"); + let mut dated_file = File::create(&dated_file_path).expect("Failed to create dated summary file"); + + println!("{}", format!("Summary will be saved to: {}", dated_file_path.display()).cyan()); + + // Write header to both files + for f in [&mut file, &mut dated_file] { + writeln!(f, "# Git Commit Summaries — {}\n", date_str).expect("Failed to write to file"); + writeln!(f, "-----------------------------------------------------------------------").expect("Failed to write to file"); + writeln!(f, "-----------------------------------------------------------------------").expect("Failed to write to file"); + writeln!(f, " ").expect("Failed to write to file"); + writeln!(f, "PRESS CMD+SHIFT+V TO VIEW IN MARKDOWN").expect("Failed to write to file"); + writeln!(f, " ").expect("Failed to write to file"); + writeln!(f, "_______________________________________________________________________").expect("Failed to write to file"); + writeln!(f, "-----------------------------------------------------------------------").expect("Failed to write to file"); + writeln!(f, "Total number of commits: {}\n", commit_hashes.len()).expect("Failed to write to file"); + } let mut tasks = Vec::new(); @@ -195,10 +212,12 @@ async fn main() { for result in results { if let Ok(Some((index, commit_hash, summary))) = result { println!("{}", format!("processing commit {} of {}: {}", index + 1, commit_hashes.len(), commit_hash).cyan()); - writeln!(file, "
\nsummary for commit {} ({})\n\n{}\n
\n", index + 1, commit_hash, summary) - .expect("Failed to write to file"); - writeln!(file, "------------------------------------------------------------------------\n") - .expect("Failed to write to file"); + for f in [&mut file, &mut dated_file] { + writeln!(f, "
\nsummary for commit {} ({})\n\n{}\n
\n", index + 1, commit_hash, summary) + .expect("Failed to write to file"); + writeln!(f, "------------------------------------------------------------------------\n") + .expect("Failed to write to file"); + } combined_changes.push(summary); commit_state.processed_commits.push(commit_hash); } @@ -209,13 +228,16 @@ async fn main() { let overall_summary = summarize_changes(&combined_changes.join("\n")).await .unwrap_or_else(|e| format!("Error generating overall summary: {}", e)); - writeln!(file, "# Overall Summary of Changes\n\n{}", overall_summary) - .expect("Failed to write overall summary to file"); + for f in [&mut file, &mut dated_file] { + writeln!(f, "# Overall Summary of Changes\n\n{}", overall_summary) + .expect("Failed to write overall summary to file"); + } open_md_in_preview(file_path_str); println!("{}", "Job finished successfully!".green()); println!("{}", format!("Summary file created at: {}", file_path_str).green()); + println!("{}", format!("Dated copy saved to: {}", dated_file_path.display()).green()); save_commit_state(&data_dir, &commit_state); }