diff --git a/devgen/modules/changelog_generator.py b/devgen/modules/changelog_generator.py index c39216f..6c3634a 100644 --- a/devgen/modules/changelog_generator.py +++ b/devgen/modules/changelog_generator.py @@ -120,7 +120,7 @@ class ChangelogGenerator: ) -> str: """Generates markdown changelog from parsed commits.""" date_str = datetime.now().strftime("%Y-%m-%d") - md = [f"# {version} ({date_str})\n"] + md = [f"## {version} ({date_str})\n"] # Order: Breaking, Features, Fixes, Docs, Others order = [ @@ -163,14 +163,19 @@ class ChangelogGenerator: if output_file: path = Path(output_file) - # If file exists, prepend? For now, just overwrite or append logic could be complex. - # Let's implement prepend logic if file exists. if path.exists(): old_content = path.read_text(encoding="utf-8") - new_content = old_content + "\n\n" + md_content + # Prepend the new content, assume # CHANGELOG is at the top or needs to be + if old_content.strip().startswith("# CHANGELOG"): + lines = old_content.split("\n", 1) + header = lines[0] + rest = lines[1] if len(lines) > 1 else "" + new_content = f"{header}\n\n{md_content}\n{rest.lstrip()}" + else: + new_content = f"# CHANGELOG\n\n{md_content}\n\n{old_content}" path.write_text(new_content, encoding="utf-8") else: - path.write_text(md_content, encoding="utf-8") + path.write_text(f"# CHANGELOG\n\n{md_content}", encoding="utf-8") self.logger.info(f"Changelog written to {output_file}") print(f" Changelog updated: {output_file}") diff --git a/devgen/modules/commit_generator.py b/devgen/modules/commit_generator.py index 2f97b5b..9f30950 100644 --- a/devgen/modules/commit_generator.py +++ b/devgen/modules/commit_generator.py @@ -39,7 +39,6 @@ IGNORE_PATTERNS = [ ] - class CommitEngine: """ Engine for generating AI-powered commit messages. @@ -98,11 +97,11 @@ class CommitEngine: ] ) files = [f.strip() for f in out.split("\n") if f.strip()] - + # Also get staged files (in case of a previous failed run) staged_out = run_git_command(["git", "diff", "--name-only", "--cached"]) staged_files = [f.strip() for f in staged_out.split("\n") if f.strip()] - + # Combine and deduplicate all_files = list(set(files + staged_files)) return all_files diff --git a/devgen/modules/license_generator.py b/devgen/modules/license_generator.py index 096ba0f..83feafd 100644 --- a/devgen/modules/license_generator.py +++ b/devgen/modules/license_generator.py @@ -8,9 +8,7 @@ class LicenseGenerator: """Generates license files from templates.""" def __init__(self): - self.templates_dir = ( - Path(__file__).parent.parent / "prompt_templates" / "licenses" - ) + self.templates_dir = Path(__file__).parent.parent / "templates" / "licenses" def list_licenses(self) -> List[Dict[str, str]]: """Lists available license templates."""