diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 575d1175..7b189fca 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -52,6 +52,10 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: markdown_text += f"## PR Review\n\n" markdown_text += "\n\n" markdown_text += """""" + + if not output_data or not output_data.get('review', {}): + return "" + for key, value in output_data['review'].items(): if value is None or value == '' or value == {} or value == []: continue diff --git a/tests/unittest/test_convert_to_markdown.py b/tests/unittest/test_convert_to_markdown.py index 954cee66..bbc0ace1 100644 --- a/tests/unittest/test_convert_to_markdown.py +++ b/tests/unittest/test_convert_to_markdown.py @@ -45,54 +45,33 @@ Additional aspects: class TestConvertToMarkdown: # Tests that the function works correctly with a simple dictionary input def test_simple_dictionary_input(self): - input_data = { - 'Main theme': 'Test', - 'Type of PR': 'Test type', - 'Relevant tests added': 'no', - 'Focused PR': 'Yes', - 'General PR suggestions': 'general suggestion...', - 'Code feedback': [ - { - 'Code example': { - 'Before': 'Code before', - 'After': 'Code after' - } - }, - { - 'Code example': { - 'Before': 'Code before 2', - 'After': 'Code after 2' - } - } - ] - } - expected_output = """\ -- ๐ŸŽฏ **Main theme:** Test\n\ -- ๐Ÿ“Œ **Type of PR:** Test type\n\ -- ๐Ÿงช **Relevant tests added:** no\n\ -- โœจ **Focused PR:** Yes\n\ -- **General PR suggestions:** general suggestion...\n\n\n
๐Ÿค– Code feedback: - **Code example:**\n - **Before:**\n ```\n Code before\n ```\n - **After:**\n ```\n Code after\n ```\n\n - **Code example:**\n - **Before:**\n ```\n Code before 2\n ```\n - **After:**\n ```\n Code after 2\n ```\n\n
\ -""" + input_data = {'review': { + 'estimated_effort_to_review_[1-5]': '1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n', + 'relevant_tests_added': 'No\n', 'possible_issues': 'No\n', 'security_concerns': 'No\n'}, 'code_feedback': [ + {'relevant_file': '``pr_agent/git_providers/git_provider.py\n``', 'language': 'python\n', + 'suggestion': "Consider raising an exception or logging a warning when 'pr_url' attribute is not found. This can help in debugging issues related to the absence of 'pr_url' in instances where it's expected. [important]\n", + 'relevant_line': '[return ""](https://github.com/Codium-ai/pr-agent-pro/pull/102/files#diff-52d45f12b836f77ed1aef86e972e65404634ea4e2a6083fb71a9b0f9bb9e062fR199)'}]} + + expected_output = '## PR Review\n\n
     PR feedback                    
\n\n\n\n\n\n
     PR feedback                    
โฑ๏ธ Estimated effort to review [1-5]\n\n1, because the changes are minimal and straightforward, focusing on a single functionality addition.\n\n\n
๐Ÿงช Relevant tests added\n\nNo\n\n\n
๐Ÿ” Possible issues\n\nNo\n\n\n
๐Ÿ”’ Security concerns\n\nNo\n\n\n
\n\n\n
Code feedback:\n\n
relevant filepr_agent/git_providers/git_provider.py\n
suggestion      \n\n\n\nConsider raising an exception or logging a warning when \'pr_url\' attribute is not found. This can help in debugging issues related to the absence of \'pr_url\' in instances where it\'s expected. [important]\n\n\n
relevant linereturn ""

\n\n
' + assert convert_to_markdown(input_data).strip() == expected_output.strip() # Tests that the function works correctly with an empty dictionary input def test_empty_dictionary_input(self): input_data = {} - expected_output = "" - assert convert_to_markdown(input_data).strip() == expected_output.strip() - def test_dictionary_input_containing_only_empty_dictionaries(self): - input_data = { - 'Main theme': {}, - 'Type of PR': {}, - 'Relevant tests added': {}, - 'Focused PR': {}, - 'General PR suggestions': {}, - 'Code suggestions': {} - } expected_output = '' + + assert convert_to_markdown(input_data).strip() == expected_output.strip() + def test_dictionary_with_empty_dictionaries(self): + input_data = {'review': {}, 'code_feedback': [{}]} + + expected_output = '' + + + assert convert_to_markdown(input_data).strip() == expected_output.strip() class TestBR: def test_br1(self): @@ -106,8 +85,9 @@ class TestBR: # print(file_change_description_br) def test_br2(self): - file_change_description = ('- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' - 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') + file_change_description = ( + '- Created a - new -class `ColorPaletteResourcesCollection ColorPaletteResourcesCollection ' + 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection`') file_change_description_br = insert_br_after_x_chars(file_change_description) expected_output = ('
  • Created a - new -class ColorPaletteResourcesCollection
    ' 'ColorPaletteResourcesCollection ColorPaletteResourcesCollection '