Skip to content

Commit

Permalink
fix: handle deleted files in git patch processing and update section …
Browse files Browse the repository at this point in the history
…header logic
  • Loading branch information
mrT23 committed Aug 27, 2024
1 parent 53a974c commit c2f5253
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pr_agent/algo/git_patch_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def _calc_context_limits(patch_lines_before):
for i,line, in enumerate(lines_before):
if section_header in line:
found_header = True
extended_start1 = extended_start1 + i
# Update start and size in one line each
extended_start1, extended_start2 = extended_start1 + i, extended_start2 + i
extended_size1, extended_size2 = extended_size1 - i, extended_size2 - i
get_logger().debug(f"Found section header in line {i} before the hunk")
section_header = ''
break
Expand Down Expand Up @@ -236,6 +238,10 @@ def convert_to_hunks_with_lines_numbers(patch: str, file) -> str:
line6
...
"""
# if the file was deleted, return a message indicating that the file was deleted
if hasattr(file, 'edit_type') and file.edit_type == EDIT_TYPE.DELETED:
return f"\n\n## file '{file.filename.strip()}' was deleted\n"

patch_with_lines_str = f"\n\n## file: '{file.filename.strip()}'\n"
patch_lines = patch.splitlines()
RE_HUNK_HEADER = re.compile(
Expand Down

0 comments on commit c2f5253

Please sign in to comment.