mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-17 05:15:19 +00:00
feat: Enhance code feedback formatting in utils.py
This commit is contained in:
parent
a7a0de764c
commit
654938f27c
1 changed files with 43 additions and 15 deletions
|
|
@ -59,7 +59,7 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
|
||||||
if key.lower() == 'code feedback':
|
if key.lower() == 'code feedback':
|
||||||
if gfm_supported:
|
if gfm_supported:
|
||||||
markdown_text += f"\n\n- "
|
markdown_text += f"\n\n- "
|
||||||
markdown_text += f"<details><summary> { emoji } Code feedback:</summary>\n\n"
|
markdown_text += f"<details><summary> { emoji } Code feedback:</summary>"
|
||||||
else:
|
else:
|
||||||
markdown_text += f"\n\n- **{emoji} Code feedback:**\n\n"
|
markdown_text += f"\n\n- **{emoji} Code feedback:**\n\n"
|
||||||
else:
|
else:
|
||||||
|
|
@ -91,6 +91,34 @@ def parse_code_suggestion(code_suggestions: dict, gfm_supported: bool=True) -> s
|
||||||
str: A string containing the markdown formatted text generated from the input dictionary.
|
str: A string containing the markdown formatted text generated from the input dictionary.
|
||||||
"""
|
"""
|
||||||
markdown_text = ""
|
markdown_text = ""
|
||||||
|
if gfm_supported and 'relevant line' in code_suggestions:
|
||||||
|
# markdown_text=markdown_text.strip()
|
||||||
|
markdown_text += '<table>'
|
||||||
|
relevant_file = ''
|
||||||
|
for sub_key, sub_value in code_suggestions.items():
|
||||||
|
try:
|
||||||
|
if sub_key.lower() == 'relevant file':
|
||||||
|
relevant_file = sub_value.strip('`').strip('"').strip("'")
|
||||||
|
markdown_text += f"<tr><td>{sub_key}</td><td>{relevant_file}</td></tr>"
|
||||||
|
# continue
|
||||||
|
elif sub_key.lower() == 'suggestion':
|
||||||
|
markdown_text += f"<tr><td>{sub_key} </td><td><strong>{sub_value}</strong></td></tr>"
|
||||||
|
elif sub_key.lower() == 'relevant line':
|
||||||
|
markdown_text += f"<tr><td>relevant line</td>"
|
||||||
|
sub_value_list = sub_value.split('](')
|
||||||
|
relevant_line = sub_value_list[0].lstrip('`').lstrip('[')
|
||||||
|
if len(sub_value_list) > 1:
|
||||||
|
link = sub_value_list[1].rstrip(')').strip('`')
|
||||||
|
markdown_text += f"<td><a href={link}>{relevant_line}</a></td>"
|
||||||
|
else:
|
||||||
|
markdown_text += f"<td>{relevant_line}</td>"
|
||||||
|
markdown_text += "</tr>"
|
||||||
|
except Exception as e:
|
||||||
|
get_logger().exception(f"Failed to parse code suggestion: {e}")
|
||||||
|
pass
|
||||||
|
markdown_text += '</table>'
|
||||||
|
markdown_text += "<hr>"
|
||||||
|
else:
|
||||||
for sub_key, sub_value in code_suggestions.items():
|
for sub_key, sub_value in code_suggestions.items():
|
||||||
if isinstance(sub_value, dict): # "code example"
|
if isinstance(sub_value, dict): # "code example"
|
||||||
markdown_text += f" - **{sub_key}:**\n"
|
markdown_text += f" - **{sub_key}:**\n"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue