From caaee4e43d5d453404ed505ee5709bd978a48d34 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 15 Sep 2023 17:09:58 +0300 Subject: [PATCH 1/6] Estimated time to review --- pr_agent/algo/utils.py | 1 + pr_agent/settings/configuration.toml | 1 + pr_agent/settings/pr_reviewer_prompts.toml | 8 ++++++++ pr_agent/tools/pr_reviewer.py | 1 + 4 files changed, 11 insertions(+) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 1dfc6dc1..7af40f67 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -42,6 +42,7 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: "General suggestions": "💡", "Insights from user's answers": "📝", "Code feedback": "🤖", + "Estimated time to review": "⏱️", } for key, value in output_data.items(): diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 73371907..40abcce8 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -18,6 +18,7 @@ require_focused_review=false require_score_review=false require_tests_review=true require_security_review=true +require_estimate_time_to_review=false num_code_suggestions=4 inline_code_comments = false ask_and_reflect=false diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 7c21f433..a89ea7eb 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -85,6 +85,14 @@ PR Analysis: code diff changes are too scattered, then the PR is not focused. Explain your answer shortly. {%- endif %} +{%- if require_estimate_time_to_review %} + Estimated time to review: + type: string + description: >- + Estimate, in minutes, how much time it would take for an experienced developer to review this PR, and provide meaningful feedback. + Take into account the size, complexity, quality and possible needed changes of the PR code diff. + Explain your answer shortly (1-2 sentences). +{%- endif %} PR Feedback: General suggestions: type: string diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 7f790d3b..fb8984a2 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -59,6 +59,7 @@ class PRReviewer: "require_tests": get_settings().pr_reviewer.require_tests_review, "require_security": get_settings().pr_reviewer.require_security_review, "require_focused": get_settings().pr_reviewer.require_focused_review, + "require_estimate_time_to_review": get_settings().pr_reviewer.require_estimate_time_to_review, 'num_code_suggestions': get_settings().pr_reviewer.num_code_suggestions, 'question_str': question_str, 'answer_str': answer_str, From ea91a385419b55af822b28901c696953050b1ad3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 17 Sep 2023 16:31:58 +0300 Subject: [PATCH 2/6] Estimated effort to review --- pr_agent/algo/utils.py | 2 +- pr_agent/settings/configuration.toml | 2 +- pr_agent/settings/pr_reviewer_prompts.toml | 8 ++++---- pr_agent/tools/pr_reviewer.py | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 7af40f67..1e5c652a 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -42,7 +42,7 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: "General suggestions": "💡", "Insights from user's answers": "📝", "Code feedback": "🤖", - "Estimated time to review": "⏱️", + "Estimated effort to review": "⏱️", } for key, value in output_data.items(): diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 40abcce8..a272e1f9 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -18,7 +18,7 @@ require_focused_review=false require_score_review=false require_tests_review=true require_security_review=true -require_estimate_time_to_review=false +require_estimate_effort_to_review=true num_code_suggestions=4 inline_code_comments = false ask_and_reflect=false diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index a89ea7eb..90ac91cc 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -85,12 +85,12 @@ PR Analysis: code diff changes are too scattered, then the PR is not focused. Explain your answer shortly. {%- endif %} -{%- if require_estimate_time_to_review %} - Estimated time to review: +{%- if require_estimate_effort_to_review %} + Estimated effort to review [1-5]: type: string description: >- - Estimate, in minutes, how much time it would take for an experienced developer to review this PR, and provide meaningful feedback. - Take into account the size, complexity, quality and possible needed changes of the PR code diff. + 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: diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index fb8984a2..b6bca536 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -59,7 +59,7 @@ class PRReviewer: "require_tests": get_settings().pr_reviewer.require_tests_review, "require_security": get_settings().pr_reviewer.require_security_review, "require_focused": get_settings().pr_reviewer.require_focused_review, - "require_estimate_time_to_review": get_settings().pr_reviewer.require_estimate_time_to_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, 'question_str': question_str, 'answer_str': answer_str, From 4fbe7d14b57188b75f47d411b697094479a7e5d6 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 17 Sep 2023 16:41:53 +0300 Subject: [PATCH 3/6] protection for no language --- pr_agent/algo/language_handler.py | 5 +++++ pr_agent/git_providers/git_provider.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/pr_agent/algo/language_handler.py b/pr_agent/algo/language_handler.py index 586a3161..66e85025 100644 --- a/pr_agent/algo/language_handler.py +++ b/pr_agent/algo/language_handler.py @@ -42,6 +42,11 @@ def sort_files_by_main_languages(languages: Dict, files: list): files_sorted = [] 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 = [] for ext in main_extensions: main_extensions_flat.extend(ext) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 330590a1..0911d2d2 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -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. """ main_language_str = "" + if not languages: + logging.info("No languages detected") + return main_language_str + try: top_language = max(languages, key=languages.get).lower() From 291ffdd6ae240a30e7e87ac067db2199a10ef27b Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 17 Sep 2023 16:51:16 +0300 Subject: [PATCH 4/6] gfm_markdown --- pr_agent/tools/pr_description.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 26bd16bc..0b907396 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -231,10 +231,14 @@ class PRDescription: pr_body += f"## {key}:\n" if 'walkthrough' in key.lower(): # for filename, description in value.items(): + if self.git_provider.is_supported("gfm_markdown"): + pr_body += "
files:\n" for file in value: filename = file['filename'].replace("'", "`") description = file['changes in file'] pr_body += f'`{filename}`: {description}\n' + if self.git_provider.is_supported("gfm_markdown"): + pr_body +="
\n" else: # if the value is a list, join its items by comma if type(value) == list: From 818ab5a9e87831c7d449037248ad26567a674219 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 17 Sep 2023 16:56:23 +0300 Subject: [PATCH 5/6] fixed tests --- pr_agent/tools/pr_description.py | 2 +- tests/unittest/test_language_handler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 0b907396..3c388eb4 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -232,7 +232,7 @@ class PRDescription: if 'walkthrough' in key.lower(): # for filename, description in value.items(): if self.git_provider.is_supported("gfm_markdown"): - pr_body += "
files:\n" + pr_body += "
files:\n\n" for file in value: filename = file['filename'].replace("'", "`") description = file['changes in file'] diff --git a/tests/unittest/test_language_handler.py b/tests/unittest/test_language_handler.py index 875ec1a7..fdde7bb0 100644 --- a/tests/unittest/test_language_handler.py +++ b/tests/unittest/test_language_handler.py @@ -61,7 +61,7 @@ class TestSortFilesByMainLanguages: type('', (object,), {'filename': 'file1.py'})(), 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 # Tests that function handles empty files list From c0511c954e7b602d1b91f4203f4553f8fb535460 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 17 Sep 2023 17:08:02 +0300 Subject: [PATCH 6/6] icon --- pr_agent/algo/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 1e5c652a..c7923d16 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -42,7 +42,7 @@ def convert_to_markdown(output_data: dict, gfm_supported: bool=True) -> str: "General suggestions": "💡", "Insights from user's answers": "📝", "Code feedback": "🤖", - "Estimated effort to review": "⏱️", + "Estimated effort to review [1-5]": "⏱️", } for key, value in output_data.items():