Skip to content

Commit 87d550b

Browse files
committed
refactor: split changelog helpers
Separate changelog generation from output emission so release-note collection and writing logic can evolve independently. Made-with: Cursor
1 parent cb932c0 commit 87d550b

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
- [x] `src/commands/misc/feedback/apply.rs`: split acceptance/rejection counters from store mutation helpers.
9090
- [x] `src/commands/misc/discussion/command.rs`: separate the interactive loop from single-shot execution.
9191
- [x] `src/commands/misc/discussion/selection.rs`: split file loading/ID repair from selection rules.
92-
- [ ] `src/commands/misc/changelog.rs`: evaluate splitting changelog collection from output formatting.
92+
- [x] `src/commands/misc/changelog.rs`: evaluate splitting changelog collection from output formatting.
9393
- [x] `src/commands/eval/command.rs`: separate CLI option prep, fixture execution, and report lifecycle.
9494
- [x] `src/commands/feedback_eval/command.rs`: separate input loading from report/output orchestration.
9595

src/commands/misc/changelog.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
#[path = "changelog/generate.rs"]
2+
mod generate;
3+
#[path = "changelog/output.rs"]
4+
mod output;
5+
16
use anyhow::Result;
27
use std::path::PathBuf;
38
use tracing::info;
49

5-
use crate::core;
10+
use generate::generate_changelog_output;
11+
use output::emit_changelog_output;
612

713
pub async fn changelog_command(
814
from: Option<String>,
@@ -11,24 +17,6 @@ pub async fn changelog_command(
1117
output_path: Option<PathBuf>,
1218
) -> Result<()> {
1319
info!("Generating changelog/release notes");
14-
15-
let generator = core::ChangelogGenerator::new(".")?;
16-
17-
let output = if let Some(version) = release {
18-
info!("Generating release notes for version {}", version);
19-
generator.generate_release_notes(&version, from.as_deref())?
20-
} else {
21-
let to_ref = to.as_deref().unwrap_or("HEAD");
22-
info!("Generating changelog from {:?} to {}", from, to_ref);
23-
generator.generate_changelog(from.as_deref(), to_ref)?
24-
};
25-
26-
if let Some(path) = output_path {
27-
tokio::fs::write(path, output).await?;
28-
info!("Changelog written to file");
29-
} else {
30-
println!("{}", output);
31-
}
32-
33-
Ok(())
20+
let output = generate_changelog_output(from.as_deref(), to.as_deref(), release.as_deref())?;
21+
emit_changelog_output(output_path.as_deref(), &output).await
3422
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use anyhow::Result;
2+
use tracing::info;
3+
4+
use crate::core;
5+
6+
pub(super) fn generate_changelog_output(
7+
from: Option<&str>,
8+
to: Option<&str>,
9+
release: Option<&str>,
10+
) -> Result<String> {
11+
let generator = core::ChangelogGenerator::new(".")?;
12+
13+
if let Some(version) = release {
14+
info!("Generating release notes for version {}", version);
15+
generator.generate_release_notes(version, from)
16+
} else {
17+
let to_ref = to.unwrap_or("HEAD");
18+
info!("Generating changelog from {:?} to {}", from, to_ref);
19+
generator.generate_changelog(from, to_ref)
20+
}
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use anyhow::Result;
2+
use std::path::Path;
3+
use tracing::info;
4+
5+
pub(super) async fn emit_changelog_output(output_path: Option<&Path>, output: &str) -> Result<()> {
6+
if let Some(path) = output_path {
7+
tokio::fs::write(path, output).await?;
8+
info!("Changelog written to file");
9+
} else {
10+
println!("{}", output);
11+
}
12+
13+
Ok(())
14+
}

0 commit comments

Comments
 (0)