initial
This commit is contained in:
23 files changed
+2117
No files matched your search
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Changelog generation using AI.
|
||||
"""
|
||||
|
||||
from .generator import ChangelogGenerator
|
||||
|
||||
__all__ = [
|
||||
"ChangelogGenerator"
|
||||
]
|
||||
@@ -0,0 +1,111 @@
|
||||
"""
|
||||
Changelog generation CLI.
|
||||
"""
|
||||
import click
|
||||
from rich.console import Console
|
||||
from rich.prompt import Prompt, Confirm
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
from .generator import ChangelogGenerator
|
||||
from ..commitgen.config import CommitGenConfig
|
||||
|
||||
console = Console()
|
||||
|
||||
@click.group()
|
||||
def cli():
|
||||
"""Generate changelogs."""
|
||||
pass
|
||||
|
||||
@cli.command()
|
||||
@click.option("--version", "-v", required=True, help="Version number")
|
||||
@click.option("--output", "-o", default="CHANGELOG.md", help="Output file path")
|
||||
@click.option("--temperature", "-t", type=float, default=0.7, help="AI temperature")
|
||||
def generate(version: str, output: str, temperature: float):
|
||||
"""Generate a changelog interactively."""
|
||||
with Progress(
|
||||
SpinnerColumn(),
|
||||
TextColumn("[progress.description]{task.description}"),
|
||||
console=console
|
||||
) as progress:
|
||||
# Initialize services
|
||||
progress.add_task("Initializing...", total=None)
|
||||
config = CommitGenConfig()
|
||||
generator = ChangelogGenerator(config)
|
||||
|
||||
# Collect changes
|
||||
console.print("\n[bold]Enter your changes (one per line). Start each line with an emoji to indicate the type:[/]")
|
||||
console.print("✨ Added")
|
||||
console.print("🔄 Changed")
|
||||
console.print("🐛 Fixed")
|
||||
console.print("🚀 Performance")
|
||||
console.print("📝 Documentation")
|
||||
console.print("🔧 Maintenance")
|
||||
console.print("🗑️ Removed")
|
||||
console.print("🔒 Security")
|
||||
console.print("\nPress Ctrl+D (Unix) or Ctrl+Z (Windows) when done.\n")
|
||||
|
||||
changes_text = []
|
||||
while True:
|
||||
try:
|
||||
line = Prompt.ask("")
|
||||
if line:
|
||||
changes_text.append(line)
|
||||
except EOFError:
|
||||
break
|
||||
|
||||
if not changes_text:
|
||||
console.print("[yellow]No changes provided. Exiting.")
|
||||
return
|
||||
|
||||
# Parse changes
|
||||
progress.add_task("Parsing changes...", total=None)
|
||||
changes = generator.parse_changes_from_text("\n".join(changes_text))
|
||||
|
||||
# Generate changelog
|
||||
progress.add_task("Generating changelog...", total=None)
|
||||
generator.update_changelog_file(version, changes, output, temperature)
|
||||
|
||||
console.print(f"\n[green]Generated changelog at {output}")
|
||||
|
||||
@cli.command()
|
||||
@click.option("--version", "-v", required=True, help="Version number")
|
||||
@click.option("--input", "-i", required=True, help="Input file with changes")
|
||||
@click.option("--output", "-o", default="CHANGELOG.md", help="Output file path")
|
||||
@click.option("--temperature", "-t", type=float, default=0.7, help="AI temperature")
|
||||
def generate_from_file(version: str, input: str, output: str, temperature: float):
|
||||
"""Generate a changelog from a file."""
|
||||
with Progress(
|
||||
SpinnerColumn(),
|
||||
TextColumn("[progress.description]{task.description}"),
|
||||
console=console
|
||||
) as progress:
|
||||
# Initialize services
|
||||
progress.add_task("Initializing...", total=None)
|
||||
config = CommitGenConfig()
|
||||
generator = ChangelogGenerator(config)
|
||||
|
||||
# Read changes from file
|
||||
progress.add_task("Reading changes...", total=None)
|
||||
try:
|
||||
with open(input, "r") as f:
|
||||
changes_text = f.read()
|
||||
except FileNotFoundError:
|
||||
console.print(f"[red]Input file not found: {input}")
|
||||
return
|
||||
|
||||
# Parse changes
|
||||
progress.add_task("Parsing changes...", total=None)
|
||||
changes = generator.parse_changes_from_text(changes_text)
|
||||
|
||||
if not changes:
|
||||
console.print("[yellow]No changes found in input file.")
|
||||
return
|
||||
|
||||
# Generate changelog
|
||||
progress.add_task("Generating changelog...", total=None)
|
||||
generator.update_changelog_file(version, changes, output, temperature)
|
||||
|
||||
console.print(f"\n[green]Generated changelog at {output}")
|
||||
|
||||
# Add command aliases
|
||||
cli.add_command(generate, name="g")
|
||||
cli.add_command(generate_from_file, name="f")
|
||||
@@ -0,0 +1,139 @@
|
||||
"""
|
||||
Changelog generation using AI.
|
||||
"""
|
||||
from typing import List, Dict, Optional
|
||||
from ..shared.ai import AIService
|
||||
from ..shared.config import Config
|
||||
from ..shared.git import GitService
|
||||
|
||||
class ChangelogGenerator(AIService):
|
||||
"""AI-powered changelog generator."""
|
||||
|
||||
def __init__(self, config: Config):
|
||||
"""Initialize changelog generator."""
|
||||
super().__init__(config)
|
||||
|
||||
def generate_changelog(self, version: str, changes: List[Dict[str, str]], temperature: Optional[float] = None) -> str:
|
||||
"""Generate a changelog from a list of changes.
|
||||
|
||||
Args:
|
||||
version: Version number for the changelog
|
||||
changes: List of changes, each with 'type' and 'description'
|
||||
temperature: AI temperature for generation
|
||||
|
||||
Returns:
|
||||
Generated changelog content
|
||||
"""
|
||||
system_prompt = """You are a helpful AI that generates changelogs.
|
||||
Follow these rules:
|
||||
1. Group changes by type (Added, Changed, Fixed, etc.)
|
||||
2. Keep descriptions concise but informative
|
||||
3. Use past tense
|
||||
4. Start each entry with a verb
|
||||
5. Use emojis for each type:
|
||||
- ✨ Added
|
||||
- 🔄 Changed
|
||||
- 🐛 Fixed
|
||||
- 🚀 Performance
|
||||
- 📝 Documentation
|
||||
- 🔧 Maintenance
|
||||
- 🗑️ Removed
|
||||
- 🔒 Security"""
|
||||
|
||||
# Format changes for the prompt
|
||||
changes_text = "\n".join(
|
||||
f"{change['type']}: {change['description']}"
|
||||
for change in changes
|
||||
)
|
||||
|
||||
user_prompt = f"Generate a changelog for version {version} with these changes:\n\n{changes_text}"
|
||||
|
||||
return self.generate_completion(
|
||||
system_prompt,
|
||||
user_prompt,
|
||||
temperature=temperature
|
||||
)
|
||||
|
||||
def update_changelog_file(self, version: str, changes: List[Dict[str, str]], output_file: str, temperature: Optional[float] = None) -> None:
|
||||
"""Generate and update a changelog file.
|
||||
|
||||
Args:
|
||||
version: Version number for the changelog
|
||||
changes: List of changes, each with 'type' and 'description'
|
||||
output_file: Path to the changelog file
|
||||
temperature: AI temperature for generation
|
||||
"""
|
||||
changelog_content = self.generate_changelog(version, changes, temperature)
|
||||
|
||||
# Read existing changelog if it exists
|
||||
try:
|
||||
with open(output_file, "r") as f:
|
||||
existing_content = f.read()
|
||||
except FileNotFoundError:
|
||||
existing_content = ""
|
||||
|
||||
# Add new changelog entry at the top
|
||||
new_content = f"## {version}\n\n{changelog_content}\n\n"
|
||||
if existing_content:
|
||||
new_content += existing_content
|
||||
|
||||
# Write updated changelog
|
||||
with open(output_file, "w") as f:
|
||||
f.write(new_content)
|
||||
|
||||
def parse_changes_from_text(self, text: str) -> List[Dict[str, str]]:
|
||||
"""Parse changes from text input.
|
||||
|
||||
Args:
|
||||
text: Text containing changes
|
||||
|
||||
Returns:
|
||||
List of changes with type and description
|
||||
"""
|
||||
changes = []
|
||||
current_type = None
|
||||
current_description = []
|
||||
|
||||
for line in text.splitlines():
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
# Check if line starts with a type marker
|
||||
type_markers = {
|
||||
"✨": "Added",
|
||||
"🔄": "Changed",
|
||||
"🐛": "Fixed",
|
||||
"🚀": "Performance",
|
||||
"📝": "Documentation",
|
||||
"🔧": "Maintenance",
|
||||
"🗑️": "Removed",
|
||||
"🔒": "Security"
|
||||
}
|
||||
|
||||
for marker, type_ in type_markers.items():
|
||||
if line.startswith(marker):
|
||||
# Save previous change if exists
|
||||
if current_type and current_description:
|
||||
changes.append({
|
||||
"type": current_type,
|
||||
"description": " ".join(current_description)
|
||||
})
|
||||
|
||||
# Start new change
|
||||
current_type = type_
|
||||
current_description = [line[len(marker):].strip()]
|
||||
break
|
||||
else:
|
||||
# Continue current change
|
||||
if current_type:
|
||||
current_description.append(line)
|
||||
|
||||
# Add last change if exists
|
||||
if current_type and current_description:
|
||||
changes.append({
|
||||
"type": current_type,
|
||||
"description": " ".join(current_description)
|
||||
})
|
||||
|
||||
return changes
|
||||
Reference in new issue
Block a user