Merge pull request #306 from Codium-ai/tr/etr

Adding Estimated Review Effort Feature and Handling Cases with No Detected Language
This commit is contained in:
mrT23
2023-09-17 17:10:52 +03:00
committed by GitHub
8 changed files with 25 additions and 1 deletions

View File

@ -42,6 +42,11 @@ def sort_files_by_main_languages(languages: Dict, files: list):
files_sorted = [] files_sorted = []
rest_files = {} rest_files = {}
# if no languages detected, put all files in the "Other" category
if not languages:
files_sorted = [({"language": "Other", "files": list(files_filtered)})]
return files_sorted
main_extensions_flat = [] main_extensions_flat = []
for ext in main_extensions: for ext in main_extensions:
main_extensions_flat.extend(ext) main_extensions_flat.extend(ext)

View File

@ -42,6 +42,7 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str:
"General suggestions": "💡", "General suggestions": "💡",
"Insights from user's answers": "📝", "Insights from user's answers": "📝",
"Code feedback": "🤖", "Code feedback": "🤖",
"Estimated effort to review [1-5]": "⏱️",
} }
for key, value in output_data.items(): for key, value in output_data.items():

View File

@ -132,6 +132,10 @@ def get_main_pr_language(languages, files) -> str:
Get the main language of the commit. Return an empty string if cannot determine. Get the main language of the commit. Return an empty string if cannot determine.
""" """
main_language_str = "" main_language_str = ""
if not languages:
logging.info("No languages detected")
return main_language_str
try: try:
top_language = max(languages, key=languages.get).lower() top_language = max(languages, key=languages.get).lower()

View File

@ -18,6 +18,7 @@ require_focused_review=false
require_score_review=false require_score_review=false
require_tests_review=true require_tests_review=true
require_security_review=true require_security_review=true
require_estimate_effort_to_review=true
num_code_suggestions=4 num_code_suggestions=4
inline_code_comments = false inline_code_comments = false
ask_and_reflect=false ask_and_reflect=false

View File

@ -85,6 +85,14 @@ PR Analysis:
code diff changes are too scattered, then the PR is not focused. Explain code diff changes are too scattered, then the PR is not focused. Explain
your answer shortly. your answer shortly.
{%- endif %} {%- endif %}
{%- if require_estimate_effort_to_review %}
Estimated effort to review [1-5]:
type: string
description: >-
Estimate, on a scale of 1-5 (inclusive), the time and effort required to review this PR by an experienced and knowledgeable developer. 1 means short and easy review , 5 means long and hard review.
Take into account the size, complexity, quality, and the needed changes of the PR code diff.
Explain your answer shortly (1-2 sentences).
{%- endif %}
PR Feedback: PR Feedback:
General suggestions: General suggestions:
type: string type: string

View File

@ -231,10 +231,14 @@ class PRDescription:
pr_body += f"## {key}:\n" pr_body += f"## {key}:\n"
if 'walkthrough' in key.lower(): if 'walkthrough' in key.lower():
# for filename, description in value.items(): # for filename, description in value.items():
if self.git_provider.is_supported("gfm_markdown"):
pr_body += "<details> <summary>files:</summary>\n\n"
for file in value: for file in value:
filename = file['filename'].replace("'", "`") filename = file['filename'].replace("'", "`")
description = file['changes in file'] description = file['changes in file']
pr_body += f'`{filename}`: {description}\n' pr_body += f'`{filename}`: {description}\n'
if self.git_provider.is_supported("gfm_markdown"):
pr_body +="</details>\n"
else: else:
# if the value is a list, join its items by comma # if the value is a list, join its items by comma
if type(value) == list: if type(value) == list:

View File

@ -59,6 +59,7 @@ class PRReviewer:
"require_tests": get_settings().pr_reviewer.require_tests_review, "require_tests": get_settings().pr_reviewer.require_tests_review,
"require_security": get_settings().pr_reviewer.require_security_review, "require_security": get_settings().pr_reviewer.require_security_review,
"require_focused": get_settings().pr_reviewer.require_focused_review, "require_focused": get_settings().pr_reviewer.require_focused_review,
"require_estimate_effort_to_review": get_settings().pr_reviewer.require_estimate_effort_to_review,
'num_code_suggestions': get_settings().pr_reviewer.num_code_suggestions, 'num_code_suggestions': get_settings().pr_reviewer.num_code_suggestions,
'question_str': question_str, 'question_str': question_str,
'answer_str': answer_str, 'answer_str': answer_str,

View File

@ -61,7 +61,7 @@ class TestSortFilesByMainLanguages:
type('', (object,), {'filename': 'file1.py'})(), type('', (object,), {'filename': 'file1.py'})(),
type('', (object,), {'filename': 'file2.java'})() type('', (object,), {'filename': 'file2.java'})()
] ]
expected_output = [{'language': 'Other', 'files': []}] expected_output = [{'language': 'Other', 'files': files}]
assert sort_files_by_main_languages(languages, files) == expected_output assert sort_files_by_main_languages(languages, files) == expected_output
# Tests that function handles empty files list # Tests that function handles empty files list