1use super::changelog::ChangelogGenerator;
2use super::releasenotes::ReleaseNotesGenerator;
3use crate::common::{CommonParams, DetailLevel};
4use crate::config::Config;
5use crate::git::GitRepo;
6use crate::ui;
7use anyhow::{Context, Result};
8use colored::Colorize;
9use std::env;
10use std::str::FromStr;
11use std::sync::Arc;
12
13pub async fn handle_changelog_command(
29 common: CommonParams,
30 from: String,
31 to: Option<String>,
32) -> Result<()> {
33 let mut config = Config::load()?;
35 common.apply_to_config(&mut config)?;
36
37 let spinner = ui::create_spinner("Generating changelog...");
39
40 if let Err(e) = config.check_environment() {
42 ui::print_error(&format!("Error: {e}"));
43 ui::print_info("\nPlease ensure the following:");
44 ui::print_info("1. Git is installed and accessible from the command line.");
45 ui::print_info("2. You are running this command from within a Git repository.");
46 ui::print_info("3. You have set up your configuration using 'git-iris config'.");
47 return Err(e);
48 }
49
50 let repo_path = env::current_dir()?;
52 let git_repo = Arc::new(GitRepo::new(&repo_path).context("Failed to create GitRepo")?);
53
54 let to = to.unwrap_or_else(|| "HEAD".to_string());
56
57 let detail_level = DetailLevel::from_str(&common.detail_level)?;
59
60 let changelog =
62 ChangelogGenerator::generate(git_repo, &from, &to, &config, detail_level).await?;
63
64 spinner.finish_and_clear();
66
67 println!("{}", "━".repeat(50).bright_purple());
68 println!("{}", &changelog);
69 println!("{}", "━".repeat(50).bright_purple());
70
71 Ok(())
72}
73
74pub async fn handle_release_notes_command(
90 common: CommonParams,
91 from: String,
92 to: Option<String>,
93) -> Result<()> {
94 let mut config = Config::load()?;
96 common.apply_to_config(&mut config)?;
97
98 let spinner = ui::create_spinner("Generating release notes...");
100
101 if let Err(e) = config.check_environment() {
103 ui::print_error(&format!("Error: {e}"));
104 ui::print_info("\nPlease ensure the following:");
105 ui::print_info("1. Git is installed and accessible from the command line.");
106 ui::print_info("2. You are running this command from within a Git repository.");
107 ui::print_info("3. You have set up your configuration using 'git-iris config'.");
108 return Err(e);
109 }
110
111 let repo_path = env::current_dir()?;
113 let git_repo = Arc::new(GitRepo::new(&repo_path).context("Failed to create GitRepo")?);
114
115 let to = to.unwrap_or_else(|| "HEAD".to_string());
117
118 let detail_level = DetailLevel::from_str(&common.detail_level)?;
120
121 let release_notes =
123 ReleaseNotesGenerator::generate(git_repo, &from, &to, &config, detail_level).await?;
124
125 spinner.finish_and_clear();
127
128 println!("{}", "━".repeat(50).bright_purple());
129 println!("{}", &release_notes);
130 println!("{}", "━".repeat(50).bright_purple());
131
132 Ok(())
133}