diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 0102c7b7..67c6f52b 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -53,10 +53,7 @@ def parse_code_suggestion(code_suggestions: dict) -> str: code_str_indented = textwrap.indent(code_str, ' ') markdown_text += f" - **{code_key}:**\n{code_str_indented}\n" else: - if "suggestion number" in sub_key.lower(): - # markdown_text += f"- **suggestion {sub_value}:**\n" # prettier formatting - pass - elif "relevant file" in sub_key.lower(): + if "relevant file" in sub_key.lower(): markdown_text += f"\n - **{sub_key}:** {sub_value}\n" else: markdown_text += f" **{sub_key}:** {sub_value}\n" diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 678c7520..62d91a38 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -47,10 +47,6 @@ You must use the following JSON schema to format your answer: "maxItems": {{ num_code_suggestions }}, "uniqueItems": true, "items": { - "suggestion number": { - "type": "int", - "description": "suggestion number, starting from 1" - }, "relevant file": { "type": "string", "description": "the relevant file name" @@ -115,7 +111,6 @@ Example output: "General PR suggestions": "..., `xxx`...", "Code suggestions": [ { - "suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]", {%- if extended_code_suggestions %} diff --git a/tests/unit/test_convert_to_markdown.py b/tests/unit/test_convert_to_markdown.py index bfd9c9b5..a40574ae 100644 --- a/tests/unit/test_convert_to_markdown.py +++ b/tests/unit/test_convert_to_markdown.py @@ -54,14 +54,12 @@ class TestConvertToMarkdown: 'General PR suggestions': 'general suggestion...', 'Code suggestions': [ { - 'Suggestion number': 1, 'Code example': { 'Before': 'Code before', 'After': 'Code after' } }, { - 'Suggestion number': 2, 'Code example': { 'Before': 'Code before 2', 'After': 'Code after 2' diff --git a/tests/unit/test_fix_output.py b/tests/unit/test_fix_output.py index 8141b74e..af0794ad 100644 --- a/tests/unit/test_fix_output.py +++ b/tests/unit/test_fix_output.py @@ -7,7 +7,7 @@ import pytest class TestTryFixJson: # Tests that JSON with complete 'Code suggestions' section returns expected output def test_incomplete_code_suggestions(self): - review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...' + review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...' expected_output = { 'PR Analysis': { 'Main theme': 'xxx', @@ -18,7 +18,6 @@ class TestTryFixJson: 'General PR suggestions': '..., `xxx`...', 'Code suggestions': [ { - 'suggestion number': 1, 'relevant file': 'xxx.py', 'suggestion content': 'xxx [important]' } @@ -28,7 +27,7 @@ class TestTryFixJson: assert try_fix_json(review) == expected_output def test_incomplete_code_suggestions_new_line(self): - review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n\t, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...' + review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n\t, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy [incomp...' expected_output = { 'PR Analysis': { 'Main theme': 'xxx', @@ -39,7 +38,6 @@ class TestTryFixJson: 'General PR suggestions': '..., `xxx`...', 'Code suggestions': [ { - 'suggestion number': 1, 'relevant file': 'xxx.py', 'suggestion content': 'xxx [important]' } @@ -49,7 +47,7 @@ class TestTryFixJson: assert try_fix_json(review) == expected_output def test_incomplete_code_suggestions_many_close_brackets(self): - review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy }, [}\n ,incomp.} ,..' + review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"relevant file": "xxx.py", "suggestion content": "xxx [important]"} \n, {"suggestion number": 2, "relevant file": "yyy.py", "suggestion content": "yyy }, [}\n ,incomp.} ,..' expected_output = { 'PR Analysis': { 'Main theme': 'xxx', @@ -60,7 +58,6 @@ class TestTryFixJson: 'General PR suggestions': '..., `xxx`...', 'Code suggestions': [ { - 'suggestion number': 1, 'relevant file': 'xxx.py', 'suggestion content': 'xxx [important]' } @@ -70,7 +67,7 @@ class TestTryFixJson: assert try_fix_json(review) == expected_output def test_incomplete_code_suggestions_relevant_file(self): - review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"suggestion number": 1, "relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.p' + review = '{"PR Analysis": {"Main theme": "xxx", "Description and title": "Yes", "Type of PR": "Bug fix"}, "PR Feedback": {"General PR suggestions": "..., `xxx`...", "Code suggestions": [{"relevant file": "xxx.py", "suggestion content": "xxx [important]"}, {"suggestion number": 2, "relevant file": "yyy.p' expected_output = { 'PR Analysis': { 'Main theme': 'xxx', @@ -81,7 +78,6 @@ class TestTryFixJson: 'General PR suggestions': '..., `xxx`...', 'Code suggestions': [ { - 'suggestion number': 1, 'relevant file': 'xxx.py', 'suggestion content': 'xxx [important]' } diff --git a/tests/unit/test_parse_code_suggestion.py b/tests/unit/test_parse_code_suggestion.py index 87e3cac8..aaa03f72 100644 --- a/tests/unit/test_parse_code_suggestion.py +++ b/tests/unit/test_parse_code_suggestion.py @@ -41,14 +41,6 @@ class TestParseCodeSuggestion: expected_output = "\n" # modified to expect a newline character assert parse_code_suggestion(input_data) == expected_output - # Tests that function returns correct output when 'suggestion number' key has a non-integer value - def test_non_integer_suggestion_number(self): - input_data = { - "Suggestion number": "one", - "Description": "This is a suggestion" - } - expected_output = " **Description:** This is a suggestion\n\n" - assert parse_code_suggestion(input_data) == expected_output # Tests that function returns correct output when 'before' or 'after' key has a non-string value def test_non_string_before_or_after(self): @@ -64,7 +56,6 @@ class TestParseCodeSuggestion: # Tests that function returns correct output when input dictionary does not have 'code example' key def test_no_code_example_key(self): code_suggestions = { - 'suggestion number': 1, 'suggestion': 'Suggestion 1', 'description': 'Description 1', 'before': 'Before 1', @@ -76,7 +67,6 @@ class TestParseCodeSuggestion: # Tests that function returns correct output when input dictionary has 'code example' key def test_with_code_example_key(self): code_suggestions = { - 'suggestion number': 2, 'suggestion': 'Suggestion 2', 'description': 'Description 2', 'code example': {