Skip to content

Commit

Permalink
Fix parse_diff function
Browse files Browse the repository at this point in the history
  • Loading branch information
truongnh1992 committed Oct 29, 2024
1 parent 0a56276 commit 78138b2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/review_code_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,19 @@ def parse_diff(diff_str: str) -> List[Dict[str, Any]]:
current_file = {"path": line[6:], "hunks": []}
files.append(current_file)
elif line.startswith("+++ b/"):
current_file["path"] = line[6:] # Update with the correct filename
if current_file is not None: # Check if current_file is initialized
current_file["path"] = line[6:]
elif line.startswith("@@"):
hunk_header = line
hunk_lines = []
current_file["hunks"].append({"header": hunk_header, "lines": hunk_lines})
elif current_file and current_file["hunks"]:
if current_file is not None: # Check if current_file is initialized
hunk_header = line
hunk_lines = []
current_file["hunks"].append({"header": hunk_header, "lines": hunk_lines})
elif current_file is not None and current_file["hunks"]: # Check for both conditions
current_file["hunks"][-1]["lines"].append(line)
return files



def main():
"""Main function to execute the code review process."""
pr_details = get_pr_details()
Expand Down

0 comments on commit 78138b2

Please sign in to comment.