Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tempfile = "3.3"
open = "3.0"
colored = "2.0"
futures = "0.3"
dialoguer = "0.10.4"
dialoguer = "0.10.4"
chrono = "0.4"
56 changes: 39 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) -> Result<String, String> {
let mut command = Command::new("sh");
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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, "<details>\n<summary>summary for commit {} ({})</summary>\n\n{}\n</details>\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, "<details>\n<summary>summary for commit {} ({})</summary>\n\n{}\n</details>\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);
}
Expand All @@ -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);
}
Expand Down