refactor(changelog): improve changelog generation and sanitization of AI output

This commit is contained in:
sankalp committed 2025-08-25 14:39:31 +05:45
1 parent 05a3a9f185
commit 7f6222b8ae
2 files changed
+29 -18

No files matched your search

+9 -17
View File
@@ -2,25 +2,21 @@
## v0.1.1
```
## v0.1.1
✨ Added
- Added git hooks management and auto-fix on pre-commit
- Added git hooks management CLI
- Added emoji option to CLI and config to control emoji prefixes
- Added emoji option to cli and config to control emoji prefixes
🔄 Changed
- Improved changelog generation to handle existing files and duplicate headers
🗑️ Removed
- Removed duplicate changelog entries
📝 Documentation
- Updated changelog for v0.1.1 release
- Recommended installation using pipx and uv
🔧 Maintenance
- Removed duplicate changelog entries
- Updated changelog for v0.1.1 release
```
## v0.1.0
```
## v0.1.0
✨ Added
@@ -29,7 +25,6 @@
- ✨ docs(changelog): Add ChangelogGenerator class documentation
- 🐛 docs(changelog): Updated changelog format and added ChangelogGenerator class documentation
🔄 Changed
- Changes for version 0.1.0:
- Updated commit message and changelog generation using AI 👨‍💻
@@ -43,7 +38,4 @@
- 📚 Update `LICENSE`
🗑️ Removed
- Removed unused variable in `_run_git_command` calls 🗑️
```
- Removed unused variable in `_run_git_command` calls 🗑️
+20 -1
View File
@@ -91,9 +91,28 @@ class ChangelogGenerator(AIService):
version
} with these changes:\n\n{changes_text}"
return self.generate_completion(
raw = self.generate_completion(
system_prompt, user_prompt, temperature=temperature
)
return self._clean_changelog_content(raw, version)
def _clean_changelog_content(self, text: str, version: str) -> str:
"""Sanitize AI output to avoid nested headers and code fences.
- Remove triple backtick fences
- Remove duplicate version headers inside content (e.g., '## v1.2.3')
- Trim excess surrounding whitespace
"""
cleaned = text.replace("```", "").strip()
# Drop any inner version headers
normalized_version = version.lstrip("vV")
inner_header_pattern = rf"^##\s+v?{re.escape(normalized_version)}\s*$"
lines = []
for line in cleaned.splitlines():
if re.match(inner_header_pattern, line.strip()):
continue
lines.append(line)
return "\n".join(lines).strip()
def update_changelog_file(
self,