diff --git a/pr_agent/algo/git_patch_processing.py b/pr_agent/algo/git_patch_processing.py index 480387fa..10d140b0 100644 --- a/pr_agent/algo/git_patch_processing.py +++ b/pr_agent/algo/git_patch_processing.py @@ -181,7 +181,7 @@ __old hunk__ ... """ - patch_with_lines_str = f"\n\n## {file.filename}\n" + patch_with_lines_str = f"\n\n## file: '{file.filename.strip()}'\n" patch_lines = patch.splitlines() RE_HUNK_HEADER = re.compile( r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@[ ]?(.*)") @@ -202,11 +202,11 @@ __old hunk__ if new_content_lines: if prev_header_line: patch_with_lines_str += f'\n{prev_header_line}\n' - patch_with_lines_str += '__new hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+'\n__new hunk__\n' for i, line_new in enumerate(new_content_lines): patch_with_lines_str += f"{start2 + i} {line_new}\n" if old_content_lines: - patch_with_lines_str += '__old hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+'\n__old hunk__\n' for line_old in old_content_lines: patch_with_lines_str += f"{line_old}\n" new_content_lines = [] @@ -236,11 +236,11 @@ __old hunk__ if match and new_content_lines: if new_content_lines: patch_with_lines_str += f'\n{header_line}\n' - patch_with_lines_str += '\n__new hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip()+ '\n__new hunk__\n' for i, line_new in enumerate(new_content_lines): patch_with_lines_str += f"{start2 + i} {line_new}\n" if old_content_lines: - patch_with_lines_str += '\n__old hunk__\n' + patch_with_lines_str = patch_with_lines_str.rstrip() + '\n__old hunk__\n' for line_old in old_content_lines: patch_with_lines_str += f"{line_old}\n" diff --git a/pr_agent/algo/pr_processing.py b/pr_agent/algo/pr_processing.py index ecec3015..f4ffae89 100644 --- a/pr_agent/algo/pr_processing.py +++ b/pr_agent/algo/pr_processing.py @@ -209,9 +209,9 @@ def pr_generate_compressed_diff(top_langs: list, token_handler: TokenHandler, mo if patch: if not convert_hunks_to_line_numbers: - patch_final = f"## {file.filename}\n\n{patch}\n" + patch_final = f"\n\n## file: '{file.filename.strip()}\n\n{patch.strip()}\n'" else: - patch_final = patch + patch_final = "\n\n" + patch.strip() patches.append(patch_final) total_tokens += token_handler.count_tokens(patch_final) if get_settings().config.verbosity_level >= 2: diff --git a/pr_agent/settings/pr_add_docs.toml b/pr_agent/settings/pr_add_docs.toml index 44e9f091..cc33eee5 100644 --- a/pr_agent/settings/pr_add_docs.toml +++ b/pr_agent/settings/pr_add_docs.toml @@ -5,7 +5,7 @@ Your task is to generate {{ docs_for_language }} for code components in the PR D Example for the PR Diff format: ====== -## src/file1.py +## file: 'src/file1.py' @@ -12,3 +12,4 @@ def func1(): __new hunk__ @@ -18,7 +18,6 @@ __old hunk__ -code line that was removed in the PR code line2 that remained unchanged in the PR - @@ ... @@ def func2(): __new hunk__ ... @@ -26,7 +25,7 @@ __old hunk__ ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/settings/pr_code_suggestions_prompts.toml b/pr_agent/settings/pr_code_suggestions_prompts.toml index ee311054..71d92350 100644 --- a/pr_agent/settings/pr_code_suggestions_prompts.toml +++ b/pr_agent/settings/pr_code_suggestions_prompts.toml @@ -4,7 +4,7 @@ Your task is to provide meaningful and actionable code suggestions, to improve t Example for the PR Diff format: ====== -## src/file1.py +## file: 'src/file1.py' @@ ... @@ def func1(): __new hunk__ @@ -16,7 +16,6 @@ __old hunk__ -old code line2 that was removed in the PR code line3 that remained unchanged in the PR - @@ ... @@ def func2(): __new hunk__ ... @@ -24,7 +23,7 @@ __old hunk__ ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 5312832c..427cd974 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -5,7 +5,7 @@ The review should focus on new code added in the PR diff (lines starting with '+ Example PR Diff: ====== -## src/file1.py +## file: 'src/file1.py' @@ -12,5 +12,5 @@ def func1(): code line 1 that remained unchanged in the PR @@ -14,12 +14,11 @@ code line 2 that remained unchanged in the PR +code line added in the PR code line 3 that remained unchanged in the PR - @@ ... @@ def func2(): ... -## src/file2.py +## file: 'src/file2.py' ... ====== diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index 1456f9a6..08074899 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -253,6 +253,8 @@ class PRCodeSuggestions: """ suggestion_list = [] + if not data: + return suggestion_list for suggestion in data: suggestion_list.append(suggestion) data_sorted = [[]] * len(suggestion_list)