97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
import subprocess
|
|
from datetime import datetime
|
|
from pathlib import Path
|
|
|
|
|
|
def generate_changelog(project_path: Path, output_file: str = "CHANGELOG.md") -> dict:
|
|
"""Generiert einen Git-basierten Changelog mit Commit-History."""
|
|
|
|
# Versuche git log zu holen
|
|
try:
|
|
result = subprocess.run(
|
|
["git", "-C", str(project_path), "log", "-10", "--oneline"],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5
|
|
)
|
|
|
|
if result.returncode == 0 and result.stdout.strip():
|
|
# Git log erfolgreich
|
|
recent_commits = "\n".join([f"- {line}" for line in result.stdout.strip().split("\n")[:10]])
|
|
changelog_content = f"""# 📋 Projekt-Changelog
|
|
|
|
## 🧠 Letzte Änderungen ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
|
|
|
|
### Zuletzt committed (git log):
|
|
{recent_commits}
|
|
|
|
💡 *Automatisch generiert vom Gitea-Sync-AI-Service*
|
|
"""
|
|
else:
|
|
# Fallback: statischer Changelog
|
|
changelog_content = f"""# 📋 Projekt-Changelog
|
|
|
|
## 🧠 Letzte Änderungen ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
|
|
|
|
- Dateiüberwachung aktiviert
|
|
- AI-basierte Analysen möglich via OpenWebUI
|
|
|
|
💡 *Automatisch generiert vom Gitea-Sync-AI-Service*
|
|
"""
|
|
except Exception as e:
|
|
# Fallback bei Fehler
|
|
changelog_content = f"""# 📋 Projekt-Changelog
|
|
|
|
## 🧠 Letzte Änderungen ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
|
|
|
|
- Dateiüberwachung aktiviert
|
|
- AI-basierte Analysen möglich via OpenWebUI
|
|
- Git log fehlgeschlagen: {str(e)}
|
|
|
|
💡 *Automatisch generiert vom Gitea-Sync-AI-Service*
|
|
"""
|
|
|
|
changelog_path = project_path / output_file
|
|
changelog_path.write_text(changelog_content)
|
|
return {"success": True, "path": str(changelog_path), "content": changelog_content}
|
|
|
|
|
|
def get_recent_commits(project_path: Path, count: int = 5) -> list:
|
|
"""Holt die letzten commits eines Repos."""
|
|
try:
|
|
result = subprocess.run(
|
|
["git", "-C", str(project_path), "log", f"-{count}", "--pretty=format:%h - %s"],
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=5
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
return result.stdout.strip().split("\n")
|
|
return []
|
|
except Exception:
|
|
return []
|
|
|
|
|
|
def update_changelog_with_changes(project_path: Path, changes: list) -> dict:
|
|
"""Aktualisiert den Changelog mit neuen Änderungen."""
|
|
|
|
recent_commits = get_recent_commits(project_path)
|
|
|
|
changelog_content = f"""# 📋 Projekt-Changelog
|
|
|
|
## 🧠 Letzte Änderungen ({datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
|
|
|
|
### Lokale Änderungen:
|
|
{chr(10).join(f"- {change}" for change in changes)}\n\n"""
|
|
|
|
if recent_commits:
|
|
changelog_content += "### Zuletzt committed:\n"
|
|
changelog_content += "\n".join(f"- {commit}" for commit in recent_commits[:5])
|
|
|
|
changelog_content += "\n💡 *Gemeinsam gestaltet mit KI-Sparringpartner*\n"
|
|
|
|
changelog_path = project_path / "CHANGELOG.md"
|
|
changelog_path.write_text(changelog_content)
|
|
|
|
return {"success": True, "path": str(changelog_path)} |