Skip to content

Commit c3ff5c4

Browse files
authored
Merge pull request #676 from Codium-ai/tr/bitbucket_review_suggestions
bitbucket code suggestions
2 parents 9cc147d + 345f923 commit c3ff5c4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Diff for: pr_agent/algo/utils.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
7575
if gfm_supported:
7676
markdown_text += f"\n\n"
7777
markdown_text += f"<details><summary> <strong>Code feedback:</strong></summary>\n\n"
78+
markdown_text += "<hr>"
7879
else:
7980
markdown_text += f"\n\n** Code feedback:**\n\n"
80-
markdown_text += "<hr>"
8181
for i, value in enumerate(output_data['code_feedback']):
8282
if value is None or value == '' or value == {} or value == []:
8383
continue
@@ -131,6 +131,10 @@ def parse_code_suggestion(code_suggestion: dict, i: int = 0, gfm_supported: bool
131131
markdown_text += "<hr>"
132132
else:
133133
for sub_key, sub_value in code_suggestion.items():
134+
if isinstance(sub_key, str):
135+
sub_key = sub_key.rstrip()
136+
if isinstance(sub_value,str):
137+
sub_value = sub_value.rstrip()
134138
if isinstance(sub_value, dict): # "code example"
135139
markdown_text += f" - **{sub_key}:**\n"
136140
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
142146
markdown_text += f"\n - **{sub_key}:** {sub_value} \n"
143147
else:
144148
markdown_text += f" **{sub_key}:** {sub_value} \n"
145-
if not gfm_supported:
146-
if "relevant_line" not in sub_key.lower(): # nicer presentation
147-
# markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab
148-
markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker
149+
if "relevant_line" not in sub_key.lower(): # nicer presentation
150+
# markdown_text = markdown_text.rstrip('\n') + "\\\n" # works for gitlab
151+
markdown_text = markdown_text.rstrip('\n') + " \n" # works for gitlab and bitbucker
149152

150153
markdown_text += "\n"
151154
return markdown_text

Diff for: tests/unittest/test_parse_code_suggestion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_no_code_example_key(self):
6161
'before': 'Before 1',
6262
'after': 'After 1'
6363
}
64-
expected_output = ' **suggestion:** Suggestion 1 \n **description:** Description 1 \n **before:** Before 1 \n **after:** After 1 \n\n' # noqa: E501
64+
expected_output = ' **suggestion:** Suggestion 1 \n **description:** Description 1 \n **before:** Before 1 \n **after:** After 1 \n\n' # noqa: E501
6565
assert parse_code_suggestion(code_suggestions) == expected_output
6666

6767
# Tests that function returns correct output when input dictionary has 'code example' key
@@ -74,5 +74,5 @@ def test_with_code_example_key(self):
7474
'after': 'After 2'
7575
}
7676
}
77-
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
77+
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
7878
assert parse_code_suggestion(code_suggestions) == expected_output

0 commit comments

Comments
 (0)