You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add ability to update changelog files with generated content
This change adds a new feature to automatically update CHANGELOG.md files:
- Implement update_changelog_file function to preserve header and append new
entries
- Add strip_ansi_codes utility to clean colored output for file writing
- Update CLI with --update and --file flags for the changelog command
- Add date extraction from Git commits with get_commit_date
- Improve changelog formatting with ordered change types
- Add smart date handling for version entries
The implementation intelligently handles existing changelog files by
preserving
their structure while adding new entries in Keep a Changelog format.
/// This function reads the existing changelog file (if it exists), preserves the header,
58
+
/// and prepends the new changelog content while maintaining the file structure.
59
+
///
60
+
/// # Arguments
61
+
///
62
+
/// * `changelog_content` - The new changelog content to prepend
63
+
/// * `changelog_path` - Path to the changelog file
64
+
/// * `git_repo` - `GitRepo` instance to use for retrieving commit dates
65
+
/// * `to_ref` - The "to" Git reference (commit/tag) to extract the date from
66
+
///
67
+
/// # Returns
68
+
///
69
+
/// A Result indicating success or an error
70
+
pubfnupdate_changelog_file(
71
+
changelog_content:&str,
72
+
changelog_path:&str,
73
+
git_repo:&Arc<GitRepo>,
74
+
to_ref:&str,
75
+
) -> Result<()>{
76
+
let path = Path::new(changelog_path);
77
+
let default_header = "# Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n";
78
+
79
+
// Get the date from the "to" Git reference
80
+
let commit_date = match git_repo.get_commit_date(to_ref){
81
+
Ok(date) => {
82
+
log_debug!("Got commit date for {}: {}", to_ref, date);
83
+
date
84
+
}
85
+
Err(e) => {
86
+
log_debug!("Failed to get commit date for {}: {}", to_ref, e);
0 commit comments