From 3548b88463912ef22a9a052e00ec93c65cb72478 Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Sun, 5 Nov 2023 15:48:39 +0200 Subject: [PATCH 1/3] type and labels --- pr_agent/settings/pr_custom_labels.toml | 1 - pr_agent/settings/pr_description_prompts.toml | 26 +++++++++---------- pr_agent/settings/pr_reviewer_prompts.toml | 9 ------- pr_agent/tools/pr_description.py | 10 +++---- pr_agent/tools/pr_reviewer.py | 2 +- 5 files changed, 19 insertions(+), 29 deletions(-) diff --git a/pr_agent/settings/pr_custom_labels.toml b/pr_agent/settings/pr_custom_labels.toml index 96cee17b..f295798a 100644 --- a/pr_agent/settings/pr_custom_labels.toml +++ b/pr_agent/settings/pr_custom_labels.toml @@ -39,7 +39,6 @@ PR Type: {{ custom_labels_examples }} {%- else %} - Bug fix - - Tests {%- endif %} ``` diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 3d9c3f0b..e3674182 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -18,22 +18,22 @@ PR Title: type: string description: an informative title for the PR, describing its main theme PR Type: - type: array + type: string + enum: + - Bug fix + - Tests + - Refactoring + - Enhancement + - Documentation + - Other {%- if enable_custom_labels %} - description: One or more labels that describe the PR type. Don't output the description in the parentheses. -{%- endif %} +PR Labels: + type: array + description: One or more labels that describe the PR labels. Don't output the description in the parentheses. items: type: string enum: -{%- if enable_custom_labels %} {{ custom_labels }} -{%- else %} - - Bug fix - - Tests - - Refactoring - - Enhancement - - Documentation - - Other {%- endif %} PR Description: type: string @@ -58,10 +58,10 @@ Example output: PR Title: |- ... PR Type: + ... {%- if enable_custom_labels %} +PR Labels: {{ custom_labels_examples }} -{%- else %} - - Bug fix {%- endif %} PR Description: |- ... diff --git a/pr_agent/settings/pr_reviewer_prompts.toml b/pr_agent/settings/pr_reviewer_prompts.toml index 556d824e..0ac1145f 100644 --- a/pr_agent/settings/pr_reviewer_prompts.toml +++ b/pr_agent/settings/pr_reviewer_prompts.toml @@ -51,22 +51,13 @@ PR Analysis: description: summary of the PR in 2-3 sentences. Type of PR: type: string -{%- if enable_custom_labels %} - description: One or more labels that describe the PR type. Don't output the description in the parentheses. -{%- endif %} - items: - type: string enum: -{%- if enable_custom_labels %} -{{ custom_labels }} -{%- else %} - Bug fix - Tests - Refactoring - Enhancement - Documentation - Other -{%- endif %} {%- if require_score %} Score: type: int diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 4f0081fb..e6ddf839 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -172,11 +172,11 @@ class PRDescription: pr_types = [] # If the 'PR Type' key is present in the dictionary, split its value by comma and assign it to 'pr_types' - if 'PR Type' in self.data: - if type(self.data['PR Type']) == list: - pr_types = self.data['PR Type'] - elif type(self.data['PR Type']) == str: - pr_types = self.data['PR Type'].split(',') + if 'PR Labels' in self.data: + if type(self.data['PR Labels']) == list: + pr_types = self.data['PR Labels'] + elif type(self.data['PR Labels']) == str: + pr_types = self.data['PR Labels'].split(',') return pr_types diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index 7cf561e2..0fffe779 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -156,7 +156,7 @@ class PRReviewer: variables["diff"] = self.patches_diff # update diff environment = Environment(undefined=StrictUndefined) - set_custom_labels(variables) + # set_custom_labels(variables) system_prompt = environment.from_string(get_settings().pr_review_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_review_prompt.user).render(variables) From 1d2aedf169f05b0e0a4cd16b4cbedf32c6bdc89a Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Mon, 6 Nov 2023 11:35:22 +0200 Subject: [PATCH 2/3] Don't Display pr labels in the text --- pr_agent/tools/pr_description.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index e6ddf839..67e6b2a7 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -177,7 +177,11 @@ class PRDescription: pr_types = self.data['PR Labels'] elif type(self.data['PR Labels']) == str: pr_types = self.data['PR Labels'].split(',') - + elif 'PR Type' in self.data: + if type(self.data['PR Type']) == list: + pr_types = self.data['PR Type'] + elif type(self.data['PR Type']) == str: + pr_types = self.data['PR Type'].split(',') return pr_types def _prepare_pr_answer_with_markers(self) -> Tuple[str, str]: @@ -223,6 +227,9 @@ class PRDescription: # Iterate over the dictionary items and append the key and value to 'markdown_text' in a markdown format markdown_text = "" + # Don't display 'PR Labels' + if 'PR Labels' in self.data: + self.data.pop('PR Labels') for key, value in self.data.items(): markdown_text += f"## {key}\n\n" markdown_text += f"{value}\n\n" From e96b03da576502e877a5f08d87489db2471fbaae Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Mon, 6 Nov 2023 11:58:26 +0200 Subject: [PATCH 3/3] add configuration enable_pr_type --- pr_agent/settings/configuration.toml | 1 + pr_agent/tools/pr_description.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index ffe6d39d..14db286d 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -34,6 +34,7 @@ add_original_user_description=false keep_original_user_title=false use_bullet_points=true extra_instructions = "" +enable_pr_type=true # markers use_description_markers=false diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 67e6b2a7..a8b23770 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -230,6 +230,8 @@ class PRDescription: # Don't display 'PR Labels' if 'PR Labels' in self.data: self.data.pop('PR Labels') + if not get_settings().pr_description.enable_pr_type: + self.data.pop('PR Type') for key, value in self.data.items(): markdown_text += f"## {key}\n\n" markdown_text += f"{value}\n\n"