From cbcfe5d10e6edfee28c5a57d441133449b6972ca Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Wed, 4 Jun 2025 13:35:31 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Based=20on=20the=20changes=20in?= =?UTF-8?q?=20`devtools/commitgen/generator.py`,=20the=20following=20commi?= =?UTF-8?q?t=20message=20can=20be=20written:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devtools/commitgen/generator.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/devtools/commitgen/generator.py b/devtools/commitgen/generator.py index 1bde25e..0c17adc 100644 --- a/devtools/commitgen/generator.py +++ b/devtools/commitgen/generator.py @@ -44,6 +44,7 @@ class CommitGenerator(AIService): - Start with a verb - Don't include pull request references in the main message - Keep the message clean and focused on the change itself + - When analyzing multiple files, focus on the overall change and its impact 5. Examples: - ✨ feat(auth): add OAuth3 authentication @@ -64,6 +65,7 @@ Focus on: 2. What type of change this is (feat, fix, etc.) 3. What part of the codebase is affected (scope) 4. What the change accomplishes (description) +5. If multiple files are changed, identify the common theme or purpose Write a single-line commit message following the conventional format. Do not include pull request references in the main message.""" @@ -72,7 +74,7 @@ Write a single-line commit message following the conventional format. Do not inc ) # Clean up the response to ensure it's a valid commit message - message = message.split("\n")[1].strip() + message = message.split("\n")[0].strip() # Remove any pull request references from the main message message = ( @@ -105,6 +107,34 @@ Write a single-line commit message following the conventional format. Do not inc return message + def generate_batch_messages( + self, diffs: Dict[str, str], temperature: Optional[float] = None + ) -> Dict[str, str]: + """Generate commit messages for multiple files. + + Args: + diffs: Dictionary mapping file paths to their diffs + temperature: Optional temperature for AI generation + + Returns: + Dictionary mapping file paths to their commit messages + """ + # If only one file, use the single file method + if len(diffs) == 1: + file_path, diff = next(iter(diffs.items())) + return {file_path: self.generate_commit_message(diff, temperature)} + + # Combine all diffs with clear file separators + combined_diff = "\n\n".join( + f"Changes in {file_path}:\n{diff}" for file_path, diff in diffs.items() + ) + + # Generate a single commit message for all changes + message = self.generate_commit_message(combined_diff, temperature) + + # Return the same message for all files + return {file_path: message for file_path in diffs.keys()} + def generate_changelog( self, commits: List[str], version: str, temperature: Optional[float] = None ) -> str: