diff --git a/pr_agent/git_providers/gitlab_provider.py b/pr_agent/git_providers/gitlab_provider.py index c583b087..7b11ef54 100644 --- a/pr_agent/git_providers/gitlab_provider.py +++ b/pr_agent/git_providers/gitlab_provider.py @@ -115,12 +115,20 @@ class GitLabProvider(GitProvider): if not patch: patch = load_large_diff(filename, new_file_content_str, original_file_content_str) + + # count number of lines added and removed + patch_lines = patch.splitlines(keepends=True) + num_plus_lines = len([line for line in patch_lines if line.startswith('+')]) + num_minus_lines = len([line for line in patch_lines if line.startswith('-')]) diff_files.append( FilePatchInfo(original_file_content_str, new_file_content_str, patch=patch, filename=filename, edit_type=edit_type, - old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path'])) + old_filename=None if diff['old_path'] == diff['new_path'] else diff['old_path'], + num_plus_lines=num_plus_lines, + num_minus_lines=num_minus_lines, )) + self.diff_files = diff_files return diff_files diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 2225088d..cf418834 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -33,13 +33,13 @@ class PRType(str, Enum): {%- if enable_file_walkthrough %} class FileWalkthrough(BaseModel): filename: str = Field(description="the relevant file full path") - changes_in_file: str = Field(description="minimal and concise description of the changes in the relevant file") + changes_in_file: str = Field(description="minimal and concise summary of the changes in the relevant file") {%- endif %} {%- if enable_semantic_files_types %} Class FileDescription(BaseModel): filename: str = Field(description="the relevant file full path") - changes_summary: str = Field(description="minimal and concise description of the important changes in the relevant file") + changes_summary: str = Field(description="minimal and concise summary of the changes in the relevant file") label: str = Field(description="a single semantic label that represents a type of code changes that occurred in the File. Possible values (partial list): 'bug fix', 'tests', 'enhancement', 'documentation', 'error handling', 'configuration changes', 'dependencies', 'formating', 'miscellaneous', ...") {%- endif %} diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 5a074390..950b4f37 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -30,6 +30,11 @@ class PRDescription: ) self.pr_id = self.git_provider.get_pr_id() + if get_settings().pr_description.enable_semantic_files_types and not self.git_provider.is_supported( + "gfm_markdown"): + get_logger().debug(f"Disabling semantic files types for {self.pr_id}") + get_settings().pr_description.enable_semantic_files_types = False + # Initialize the AI handler self.ai_handler = AiHandler() @@ -313,10 +318,11 @@ class PRDescription: filename_publish += diff_plus_minus if self.git_provider.is_supported("gfm_markdown"): pr_body += f"
{filename_publish}" + file_change_description= self._insert_br_after_x_chars(file_change_description) if diff_plus_minus: - pr_body += f"
" + pr_body += f"" else: - pr_body += f"" + pr_body += f"" if self.git_provider.is_supported("gfm_markdown"): pr_body += "|\n" else: @@ -344,4 +350,28 @@ class PRDescription: self.file_label_dict[label].append((filename, changes_summary)) except Exception as e: get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}") - pass \ No newline at end of file + pass + + def _insert_br_after_x_chars(self, text): + """ + Insert
into a string after a word that increases its length above x characters. + """ + x = 70 + if len(text) < x: + return text + + words = text.split(' ') + new_text = "" + current_length = 0 + + for word in words: + # Check if adding this word exceeds x characters + if current_length + len(word) > x: + new_text += "
" # Insert line break + current_length = 0 # Reset counter + + # Add the word to the new text + new_text += word + " " + current_length += len(word) + 1 # Add 1 for the space + + return new_text.strip() # Remove trailing space