""" Changelog management """ from pathlib import Path from datetime import datetime import subprocess class ChangeLog: def __init__(self, repo_path: Path): self.changelog_path = repo_path / 'madomeda_changelog.txt' self.current_session = None def start_session(self): """Start a new changelog session""" # Get current commit hash result = subprocess.run( ['git', 'rev-parse', 'HEAD'], cwd=self.changelog_path.parent, capture_output=True, text=True ) commit_hash = result.stdout.strip() if result.returncode == 0 else 'no-commit' timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.current_session = f"{timestamp} (commit: {commit_hash})\n" self.entries = [] def add_entry(self, file_path: str, message: str = "frontmatter updated"): """Add a changelog entry""" if self.current_session: self.entries.append(f" {file_path} - {message}") def write(self): """Write changelog to file""" if not self.current_session or not self.entries: return content = self.current_session content += '\n'.join(self.entries) content += '\n\n' # Append to changelog file with open(self.changelog_path, 'a', encoding='utf-8') as f: f.write(content)