Skip to content

Commit

Permalink
Merge pull request #1412 from Codium-ai/tr/dedent_review
Browse files Browse the repository at this point in the history
feat: add dedent option to code snippet formatting
  • Loading branch information
mrT23 authored Dec 24, 2024
2 parents 93e6436 + 7d9288b commit c84b3d0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pr_agent/algo/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
from enum import Enum
from typing import Optional


class EDIT_TYPE(Enum):
Expand All @@ -21,4 +22,5 @@ class FilePatchInfo:
old_filename: str = None
num_plus_lines: int = -1
num_minus_lines: int = -1
language: Optional[str] = None
ai_file_summary: str = None
8 changes: 6 additions & 2 deletions pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def convert_to_markdown_v2(output_data: dict,
start_line = int(str(issue.get('start_line', 0)).strip())
end_line = int(str(issue.get('end_line', 0)).strip())

relevant_lines_str = extract_relevant_lines_str(end_line, files, relevant_file, start_line)
relevant_lines_str = extract_relevant_lines_str(end_line, files, relevant_file, start_line, dedent=True)
if git_provider:
reference_link = git_provider.get_line_link(relevant_file, start_line, end_line)
else:
Expand Down Expand Up @@ -288,7 +288,7 @@ def convert_to_markdown_v2(output_data: dict,

return markdown_text

def extract_relevant_lines_str(end_line, files, relevant_file, start_line):
def extract_relevant_lines_str(end_line, files, relevant_file, start_line, dedent=False):
try:
relevant_lines_str = ""
if files:
Expand All @@ -300,8 +300,12 @@ def extract_relevant_lines_str(end_line, files, relevant_file, start_line):
return ""
relevant_file_lines = file.head_file.splitlines()
relevant_lines_str = "\n".join(relevant_file_lines[start_line - 1:end_line])
if dedent and relevant_lines_str:
# Remove the longest leading string of spaces and tabs common to all lines.
relevant_lines_str = textwrap.dedent(relevant_lines_str)
relevant_lines_str = f"```{file.language}\n{relevant_lines_str}\n```"
break

return relevant_lines_str
except Exception as e:
get_logger().exception(f"Failed to extract relevant lines: {e}")
Expand Down

0 comments on commit c84b3d0

Please sign in to comment.