diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 34d791c4..b1df8887 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -75,9 +75,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: if gfm_supported: markdown_text += f"\n\n" markdown_text += f"
Code feedback:\n\n" + markdown_text += "
" else: markdown_text += f"\n\n** Code feedback:**\n\n" - markdown_text += "
" for i, value in enumerate(output_data['code_feedback']): if value is None or value == '' or value == {} or value == []: continue @@ -131,6 +131,10 @@ def parse_code_suggestion(code_suggestion: dict, i: int = 0, gfm_supported: bool markdown_text += "
" else: for sub_key, sub_value in code_suggestion.items(): + if isinstance(sub_key, str): + sub_key = sub_key.rstrip() + if isinstance(sub_value,str): + sub_value = sub_value.rstrip() if isinstance(sub_value, dict): # "code example" markdown_text += f" - **{sub_key}:**\n" for code_key, code_value in sub_value.items(): # 'before' and 'after' code @@ -142,10 +146,9 @@ def parse_code_suggestion(code_suggestion: dict, i: int = 0, gfm_supported: bool markdown_text += f"\n - **{sub_key}:** {sub_value} \n" else: markdown_text += f" **{sub_key}:** {sub_value} \n" - if not gfm_supported: - if "relevant_line" not in sub_key.lower(): # nicer presentation - # markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab - markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker + if "relevant_line" not in sub_key.lower(): # nicer presentation + # markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab + markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker markdown_text += "\n" return markdown_text diff --git a/tests/unittest/test_parse_code_suggestion.py b/tests/unittest/test_parse_code_suggestion.py index a7a5ecc2..5ffd9f3e 100644 --- a/tests/unittest/test_parse_code_suggestion.py +++ b/tests/unittest/test_parse_code_suggestion.py @@ -61,7 +61,7 @@ class TestParseCodeSuggestion: 'before': 'Before 1', 'after': 'After 1' } - expected_output = ' **suggestion:** Suggestion 1 \n **description:** Description 1 \n **before:** Before 1 \n **after:** After 1 \n\n' # noqa: E501 + expected_output = ' **suggestion:** Suggestion 1 \n **description:** Description 1 \n **before:** Before 1 \n **after:** After 1 \n\n' # noqa: E501 assert parse_code_suggestion(code_suggestions) == expected_output # Tests that function returns correct output when input dictionary has 'code example' key @@ -74,5 +74,5 @@ class TestParseCodeSuggestion: 'after': 'After 2' } } - expected_output = ' **suggestion:** Suggestion 2 \n **description:** Description 2 \n - **code example:**\n - **before:**\n ```\n Before 2\n ```\n - **after:**\n ```\n After 2\n ```\n\n' # noqa: E501 + expected_output = ' **suggestion:** Suggestion 2 \n **description:** Description 2 \n - **code example:**\n - **before:**\n ```\n Before 2\n ```\n - **after:**\n ```\n After 2\n ```\n\n' # noqa: E501 assert parse_code_suggestion(code_suggestions) == expected_output