feat(changelog): 使用统一的 CHANGELOG_HEADER 常量生成标准化头部
This commit is contained in:
@@ -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)?;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user