From d54e83941c4024889cce00ae135d79395df46585 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 4 Jun 2025 13:58:46 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=F0=9F=93=9D=20docs(changelog):?= =?UTF-8?q?=20Update=20changelog=20format,=20add=20ChangelogGenerator=20cl?= =?UTF-8?q?ass=20documentation,=20and=20improve=20commit=20message=20gener?= =?UTF-8?q?ation=20using=20AI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 75 ++++++++++++++++++--------------- devtools/commitgen/generator.py | 74 +++++++++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c7fa87e..a64d818 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,52 +1,57 @@ # Changelog -## 0.1.0 +## v0.1.0 -Changes for version 0.1.0: +### ✨ Added -🔧 Maintenance: +- - Updated changelog format and added ChangelogGenerator class documentation 📚 +- - Updated `README.md` file with the new commit message format and ChangelogGenerator class usage 📝 +- ## Added +- - ✨ docs(changelog): Add ChangelogGenerator class documentation +- - 🐛 docs(changelog): Updated changelog format and added ChangelogGenerator class documentation -- Cleaned up user prompt text in commit message generation -- Updated commit message and changelog generation using AI 👨‍💻 -- Removed unused variable in `_run_git_command` calls 🗑️ -- Updated `GitService` to return exit code from `_run_git_command` and improved `get_commit_history` method signature and docstring 📝 -- Updated changelog format for clarity and consistency 📚 +### 🔄 Changed -📝 Documentation: +- # Changelog +- Changes for version 0.1.0: +- - Updated commit message and changelog generation using AI 👨‍💻 +- - Updated `GitService` to return exit code from `_run_git_command` and improved `get_commit_history` method signature and docstring 📝 +- - Updated changelog format for clarity and consistency 📚 +- - Updated `LICENSE` 📄 +- ### Changed +- - 🔄 refactor(generator): Update commit message and changelog generation using AI +- - 🔄 refactor(devtools/shared/git.py): Update GitService to return exit code from `_run_git_command` and improve `get_commit_history` method signature and docstring +- - 🔄 docs(changelog): Updated changelog format for clarity and consistency +- - 📚 Update `README.md` file +- - 📚 Update `LICENSE` -- Updated changelog format and added ChangelogGenerator class documentation 📚 -- Updated `README.md` file with the new commit message format and ChangelogGenerator class usage 📝 +### 🐛 Fixed -Initial: +- ### Fixed -- Updated `LICENSE` 📄 -- Initial commit 🚀 +### 📝 Documentation -## Added +- 📝 Documentation: -- ✨ docs(changelog): Add ChangelogGenerator class documentation +### 🔧 Maintenance -### Changed +- ## 0.1.0 +- 🔧 Maintenance: +- - Cleaned up user prompt text in commit message generation +- Initial: +- - Initial commit 🚀 +- - 🔄 refactor(git.py): Remove unused variable in `_run_git_command` calls +- ### Initial Commits +- - 🚀 Initial commit +- - 🗑️ Not applicable for this version +- - 🔒 Not applicable for this version -- 🔄 refactor(generator): Update commit message and changelog generation using AI -- 🔄 refactor(git.py): Remove unused variable in `_run_git_command` calls -- 🔄 refactor(devtools/shared/git.py): Update GitService to return exit code from `_run_git_command` and improve `get_commit_history` method signature and docstring -- 🔄 docs(changelog): Updated changelog format for clarity and consistency +### 🗑️ Removed -### Fixed +- - Removed unused variable in `_run_git_command` calls 🗑️ +- ### Removed -- 🐛 docs(changelog): Updated changelog format and added ChangelogGenerator class documentation +### 🔒 Security -### Initial Commits +- ### Security -- 🚀 Initial commit -- 📚 Update `README.md` file -- 📚 Update `LICENSE` - -### Removed - -- 🗑️ Not applicable for this version - -### Security - -- 🔒 Not applicable for this version diff --git a/devtools/commitgen/generator.py b/devtools/commitgen/generator.py index fe96faa..76efe20 100644 --- a/devtools/commitgen/generator.py +++ b/devtools/commitgen/generator.py @@ -2,9 +2,10 @@ Commit message and changelog generation using AI. """ -from typing import List, Dict, Optional +from typing import List, Dict, Optional, Tuple from ..shared.ai import AIService from ..shared.config import Config +from concurrent.futures import ThreadPoolExecutor class CommitGenerator(AIService): @@ -110,18 +111,79 @@ Output ONLY the commit message in the correct format (with emoji).""" def generate_batch_messages( self, diffs: Dict[str, str], temperature: Optional[float] = None ) -> Dict[str, str]: - """Generate commit messages for multiple files.""" + """Generate commit messages for multiple files with intelligent grouping. + + This method analyzes the diffs to determine if they should be grouped into a single + commit message or kept separate based on their relationship and scope. + + Args: + diffs: Dictionary mapping file paths to their diffs + temperature: Optional temperature for generation + + Returns: + Dictionary mapping file paths to their commit messages + """ + if not diffs: + return {} + if len(diffs) == 1: file_path, diff = next(iter(diffs.items())) return {file_path: self.generate_commit_message(diff, temperature)} - combined_diff = "\n\n".join( - f"Changes in {file_path}:\n{diff}" for file_path, diff in diffs.items() + # First, analyze the diffs to determine if they should be grouped + system_prompt = """You are an expert at analyzing code changes and determining their relationships. +Analyze the provided diffs and determine if they represent related changes that should be grouped together. +Consider: +1. Are the changes part of the same feature or fix? +2. Do they share a common scope or purpose? +3. Would separating them make the commit history less meaningful? + +Respond with either: +- "GROUP" if the changes should be combined into one commit +- "SEPARATE" if the changes should have individual commit messages +Include a brief explanation of your reasoning.""" + + # Prepare the diffs for analysis + analysis_input = "\n\n".join( + f"File: {file_path}\nChanges:\n{diff}" for file_path, diff in diffs.items() ) - message = self.generate_commit_message(combined_diff, temperature) + analysis = self.generate_completion( + system_prompt, + f"Analyze these changes:\n\n{analysis_input}", + temperature=0.1, # Lower temperature for more consistent analysis + ) - return {file_path: message for file_path in diffs.keys()} + should_group = "GROUP" in analysis.upper() + + if should_group: + # Generate a single commit message for all changes + try: + # Create a structured diff that maintains file context + structured_diff = "\n\n".join( + f"=== Changes in {file_path} ===\n{diff}" + for file_path, diff in diffs.items() + ) + + message = self.generate_commit_message(structured_diff, temperature) + return {file_path: message for file_path in diffs.keys()} + except Exception as e: + # Fallback to individual messages if combined generation fails + print(f"Warning: Failed to generate combined message: {e}") + should_group = False + + if not should_group: + # Generate individual messages for each file + results = {} + for file_path, diff in diffs.items(): + try: + message = self.generate_commit_message(diff, temperature) + results[file_path] = message + except Exception as e: + # Fallback to a basic message if generation fails + print(f"Warning: Failed to generate message for {file_path}: {e}") + results[file_path] = "🔧 chore: update code" + return results def generate_changelog( self, commits: List[str], version: str, temperature: Optional[float] = None