From d47a8401794af0a9c481bbd550c45c825182f1bb Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 19 Feb 2024 19:43:31 +0200 Subject: [PATCH 1/3] bitbucket code suggestions --- pr_agent/algo/utils.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 34d791c4..4a64c4c5 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,8 @@ 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(): + sub_key = sub_key.rstrip() + 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 +144,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 From 0f815876e5932b8bb39ff97d95b6c130c11be98f Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 19 Feb 2024 19:46:57 +0200 Subject: [PATCH 2/3] bitbucket code suggestions --- pr_agent/algo/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 4a64c4c5..b1df8887 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -131,8 +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(): - sub_key = sub_key.rstrip() - sub_value = sub_value.rstrip() + 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 From 345f923569fe192f1ee29d2a2e05f38f6a966f92 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 19 Feb 2024 19:52:49 +0200 Subject: [PATCH 3/3] bitbucket code suggestions --- tests/unittest/test_parse_code_suggestion.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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