mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 21:30:40 +08:00
s
This commit is contained in:
@ -115,12 +115,20 @@ class GitLabProvider(GitProvider):
|
|||||||
if not patch:
|
if not patch:
|
||||||
patch = load_large_diff(filename, new_file_content_str, original_file_content_str)
|
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(
|
diff_files.append(
|
||||||
FilePatchInfo(original_file_content_str, new_file_content_str,
|
FilePatchInfo(original_file_content_str, new_file_content_str,
|
||||||
patch=patch,
|
patch=patch,
|
||||||
filename=filename,
|
filename=filename,
|
||||||
edit_type=edit_type,
|
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
|
self.diff_files = diff_files
|
||||||
return diff_files
|
return diff_files
|
||||||
|
|
||||||
|
@ -33,13 +33,13 @@ class PRType(str, Enum):
|
|||||||
{%- if enable_file_walkthrough %}
|
{%- if enable_file_walkthrough %}
|
||||||
class FileWalkthrough(BaseModel):
|
class FileWalkthrough(BaseModel):
|
||||||
filename: str = Field(description="the relevant file full path")
|
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 %}
|
{%- endif %}
|
||||||
|
|
||||||
{%- if enable_semantic_files_types %}
|
{%- if enable_semantic_files_types %}
|
||||||
Class FileDescription(BaseModel):
|
Class FileDescription(BaseModel):
|
||||||
filename: str = Field(description="the relevant file full path")
|
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', ...")
|
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 %}
|
{%- endif %}
|
||||||
|
|
||||||
|
@ -30,6 +30,11 @@ class PRDescription:
|
|||||||
)
|
)
|
||||||
self.pr_id = self.git_provider.get_pr_id()
|
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
|
# Initialize the AI handler
|
||||||
self.ai_handler = AiHandler()
|
self.ai_handler = AiHandler()
|
||||||
|
|
||||||
@ -313,10 +318,11 @@ class PRDescription:
|
|||||||
filename_publish += diff_plus_minus
|
filename_publish += diff_plus_minus
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
pr_body += f"<details><summary>{filename_publish}</summary>"
|
pr_body += f"<details><summary>{filename_publish}</summary>"
|
||||||
|
file_change_description= self._insert_br_after_x_chars(file_change_description)
|
||||||
if diff_plus_minus:
|
if diff_plus_minus:
|
||||||
pr_body += f"<ul>Change summary:<br>**{file_change_description}**</ul></details>"
|
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
|
||||||
else:
|
else:
|
||||||
pr_body += f"<ul>Change summary:<br>**{file_change_description}**</ul></details>"
|
pr_body += f"<ul>Changes summary:<br>**{file_change_description}**</ul></details>"
|
||||||
if self.git_provider.is_supported("gfm_markdown"):
|
if self.git_provider.is_supported("gfm_markdown"):
|
||||||
pr_body += "</ul></details>|\n"
|
pr_body += "</ul></details>|\n"
|
||||||
else:
|
else:
|
||||||
@ -345,3 +351,27 @@ class PRDescription:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
|
get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _insert_br_after_x_chars(self, text):
|
||||||
|
"""
|
||||||
|
Insert <br> 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 += "<br>" # 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
|
||||||
|
Reference in New Issue
Block a user