Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hl/pr review table #646

Merged
merged 14 commits into from
Feb 9, 2024
10 changes: 8 additions & 2 deletions pr_agent/algo/utils.py
mrT23 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,13 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
if value is None or value == '' or value == {} or value == []:
continue
if isinstance(value, dict):
markdown_text += f"## {key}\n\n"
if key.lower() == 'pr review':
markdown_text += f"## {key}\n\n"
markdown_text += "<table>\n<tr>\n"
markdown_text += """<td> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>Feedback</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </td> <td></td></tr>"""

markdown_text += convert_to_markdown(value, gfm_supported)
markdown_text += "\n</table>\n"
elif isinstance(value, list):
emoji = emojis.get(key, "")
if key.lower() == 'code feedback':
Expand Down Expand Up @@ -87,7 +92,8 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
else:
markdown_text += f"{emoji} **General suggestions:** {value}\n"
else:
markdown_text += f"- {emoji} **{key}:** {value}\n"
markdown_text += f"<tr><td> {emoji} {key}</td><td> {value}</td></tr>\n"

return markdown_text


Expand Down
37 changes: 6 additions & 31 deletions pr_agent/settings/pr_reviewer_prompts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,7 @@ Extra instructions from the user:

You must use the following YAML schema to format your answer:
```yaml
PR Analysis:
Main theme:
type: string
description: a short explanation of the PR
PR summary:
type: string
description: summary of the PR in 2-3 sentences.
Type of PR:
type: string
enum:
- Bug fix
- Tests
- Enhancement
- Documentation
- Other
PR Review:
{%- if require_score %}
Score:
type: int
Expand Down Expand Up @@ -97,14 +83,9 @@ PR Analysis:
Take into account the size, complexity, quality, and the needed changes of the PR code diff.
Explain your answer shortly (1-2 sentences). Use the format: '1, because ...'
{%- endif %}
{%- if num_code_suggestions > 0 or require_security %}
PR Feedback:
General suggestions:
type: string
description: |-
General suggestions and feedback for the contributors and maintainers of this PR.
May include important suggestions for the overall structure,
primary purpose, best practices, critical bugs, and other aspects of the PR.
Don't address PR title and description, or lack of tests. Explain your suggestions.
{% endif %}
{%- if num_code_suggestions > 0 %}
Code feedback:
type: array
Expand Down Expand Up @@ -142,13 +123,7 @@ PR Feedback:

Example output:
```yaml
PR Analysis:
Main theme: |-
xxx
PR summary: |-
xxx
Type of PR: |-
...
PR Review:
{%- if require_score %}
Score: 89
{%- endif %}
Expand All @@ -161,9 +136,9 @@ PR Analysis:
Estimated effort to review [1-5]: |-
3, because ...
{%- endif %}
{%- if num_code_suggestions > 0 or require_security %}
PR Feedback:
General PR suggestions: |-
...
{% endif %}
{%- if num_code_suggestions > 0 %}
Code feedback:
- relevant file: |-
Expand Down
10 changes: 5 additions & 5 deletions pr_agent/tools/pr_reviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def run(self) -> None:
# publish the review
if get_settings().pr_reviewer.persistent_comment and not self.incremental.is_incremental:
self.git_provider.publish_persistent_comment(pr_comment,
initial_header="## PR Analysis",
initial_header="## PR Review",
update_header=True)
else:
self.git_provider.publish_comment(pr_comment)
Expand Down Expand Up @@ -198,9 +198,9 @@ def _prepare_pr_review(self) -> str:
if security_concerns is not None:
del pr_feedback['Security concerns']
if type(security_concerns) == bool and security_concerns == False:
data.setdefault('PR Analysis', {})['Security concerns'] = 'No security concerns found'
data.setdefault('PR Review', {})['Security concerns'] = 'No security concerns found'
else:
data.setdefault('PR Analysis', {})['Security concerns'] = security_concerns
data.setdefault('PR Review', {})['Security concerns'] = security_concerns

#
if 'Code feedback' in pr_feedback:
Expand Down Expand Up @@ -376,12 +376,12 @@ def set_review_labels(self, data):
try:
review_labels = []
if get_settings().pr_reviewer.enable_review_labels_effort:
estimated_effort = data['PR Analysis']['Estimated effort to review [1-5]']
estimated_effort = data['PR Review']['Estimated effort to review [1-5]']
estimated_effort_number = int(estimated_effort.split(',')[0])
if 1 <= estimated_effort_number <= 5: # 1, because ...
review_labels.append(f'Review effort [1-5]: {estimated_effort_number}')
if get_settings().pr_reviewer.enable_review_labels_security:
security_concerns = data['PR Analysis']['Security concerns'] # yes, because ...
security_concerns = data['PR Review']['Security concerns'] # yes, because ...
security_concerns_bool = 'yes' in security_concerns.lower() or 'true' in security_concerns.lower()
if security_concerns_bool:
review_labels.append('Possible security concern')
Expand Down
Loading