feat(changelog): 使用统一的 CHANGELOG_HEADER 常量生成标准化头部

This commit is contained in:
2026-02-28 15:29:07 +08:00
parent 04410ea9e7
commit 5957d67bc3
3 changed files with 24 additions and 17 deletions

View File

@@ -162,8 +162,10 @@ impl ChangelogCommand {
if output_path.exists() {
let existing = std::fs::read_to_string(&output_path)?;
let new_content = if existing.is_empty() {
format!("# Changelog\n\n{}", changelog)
} else {
format!("{}{}", CHANGELOG_HEADER, changelog)
} else if existing.starts_with(CHANGELOG_HEADER) {
format!("{}{}", CHANGELOG_HEADER, changelog)
} else if existing.starts_with("# Changelog") {
let lines: Vec<&str> = existing.lines().collect();
let mut header_end = 0;
@@ -181,10 +183,12 @@ impl ChangelogCommand {
let rest = lines[header_end..].join("\n");
format!("{}\n{}\n{}", header, changelog, rest)
} else {
format!("{}{}", CHANGELOG_HEADER, changelog)
};
std::fs::write(&output_path, new_content)?;
} else {
let content = format!("# Changelog\n\n{}", changelog);
let content = format!("{}{}", CHANGELOG_HEADER, changelog);
std::fs::write(&output_path, content)?;
}