Skip to content

Commit

Permalink
Add unique_strings function and remove duplicate issues in utils.py; …
Browse files Browse the repository at this point in the history
…Update pr_reviewer_prompts.toml template
  • Loading branch information
mrT23 committed Mar 4, 2024
1 parent 234a4f3 commit da39149
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
23 changes: 20 additions & 3 deletions pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,20 @@ def emphasize_header(text: str) -> str:
get_logger().exception(f"Failed to emphasize header: {e}")
return text

def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:

def unique_strings(input_list: List[str]) -> List[str]:
if not input_list or not isinstance(input_list, list):
return input_list
seen = set()
unique_list = []
for item in input_list:
if item not in seen:
unique_list.append(item)
seen.add(item)
return unique_list


def convert_to_markdown(output_data: dict, gfm_supported: bool = True) -> str:
"""
Convert a dictionary of data into markdown format.
Args:
Expand Down Expand Up @@ -89,12 +102,16 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
elif 'possible issues' in key_nice.lower():
value = value.strip()
issues = value.split('\n- ')
for i, _ in enumerate(issues):
issues[i] = issues[i].strip().strip('-').strip()
issues = unique_strings(issues) # remove duplicates
number_of_issues = len(issues)
if number_of_issues > 1:
markdown_text += f"<tr><td rowspan={number_of_issues}> {emoji}&nbsp;<strong>{key_nice}</strong></td>\n"
for i, issue in enumerate(issues):
issue = issue.strip('-').strip()
issue = emphasize_header(issue.strip())
if not issue:
continue
issue = emphasize_header(issue)
if i == 0:
markdown_text += f"<td>\n\n{issue}</td></tr>\n"
else:
Expand Down
9 changes: 1 addition & 8 deletions pr_agent/settings/pr_reviewer_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,8 @@ Description:
======
{%- endif %}
{%- if commit_messages_str %}
Commit messages:
======
{{commit_messages_str}}
======
{%- endif %}
{%- if question_str %}
=====
Here are questions to better understand the PR. Use the answers to provide better feedback.
Expand Down

0 comments on commit da39149

Please sign in to comment.