Initial upload: Auto Commit Message Generator with CI/CD workflow
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
89
src/main.rs
Normal file
89
src/main.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
mod analyzer;
|
||||
mod cli;
|
||||
mod generator;
|
||||
mod git;
|
||||
mod prompt;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use cli::Args;
|
||||
use colored::Colorize;
|
||||
use git::GitRepo;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
|
||||
let git_repo = GitRepo::find_repo().context(
|
||||
"Not in a git repository. Please run this command from within a git repository.",
|
||||
)?;
|
||||
|
||||
let staged = git_repo
|
||||
.get_staged_changes()
|
||||
.context("Failed to get staged changes")?;
|
||||
|
||||
if staged.files.is_empty() {
|
||||
println!(
|
||||
"{}",
|
||||
"No staged changes found. Please stage your changes first with 'git add'.".yellow()
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if args.verbose {
|
||||
prompt::print_staged_summary(&staged);
|
||||
}
|
||||
|
||||
let analysis = analyzer::analyze_changes(&staged);
|
||||
|
||||
let commit_type = if let Some(override_type) = args.type_override {
|
||||
override_type.into()
|
||||
} else {
|
||||
analysis.commit_type
|
||||
};
|
||||
|
||||
let analysis = analyzer::AnalysisResult {
|
||||
commit_type,
|
||||
scope: args.scope_override.or(analysis.scope),
|
||||
confidence: analysis.confidence,
|
||||
description: analysis.description,
|
||||
reasons: analysis.reasons,
|
||||
};
|
||||
|
||||
let message = generator::generate_message(&analysis, &staged);
|
||||
|
||||
if args.dry_run {
|
||||
println!("{}", "\n[DRY RUN] Commit message preview:".bold().blue());
|
||||
println!("\n{}\n", message.bright_white().on_blue());
|
||||
println!("{}", "No changes were made.".yellow());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if args.no_interactive {
|
||||
println!("{}", "\nGenerated commit message:".bold().green());
|
||||
println!("\n{}\n", message.bright_white().on_blue());
|
||||
|
||||
let confirm = dialoguer::Confirm::with_theme(&dialoguer::theme::ColorfulTheme::default())
|
||||
.with_prompt("Proceed with commit?")
|
||||
.default(true)
|
||||
.interact()?;
|
||||
|
||||
if !confirm {
|
||||
println!("{}", "Commit aborted.".yellow());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
git_repo.create_commit(&message, false)?;
|
||||
println!("{}", "\nCommit created successfully!".green().bold());
|
||||
} else {
|
||||
match prompt::interactive_commit(&git_repo, analysis.commit_type, &staged)? {
|
||||
Some(final_message) => {
|
||||
git_repo.create_commit(&final_message, false)?;
|
||||
println!("{}", "\nCommit created successfully!".green().bold());
|
||||
}
|
||||
None => {
|
||||
println!("{}", "Commit aborted.".yellow());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user