diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 4e88b33e..76981f33 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -304,3 +304,18 @@ def try_fix_yaml(review_text: str) -> dict: except: pass return data + + +async def set_custom_labels(variables): + labels = get_settings().custom_labels + if not labels: + # set default labels + labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other'] + labels_list = "\n - ".join(labels) if labels else "" + labels_list = f" - {labels_list}" if labels_list else "" + variables["custom_labels"] = labels_list + return + final_labels = "" + for k, v in labels.items(): + final_labels += f" - {k} ({v['description']})\n" + variables["custom_labels"] = final_labels diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 49b9317e..0a45e55a 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -38,7 +38,24 @@ extra_instructions = "" use_description_markers=false include_generated_by_header=true -custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other'] +[custom_labels."Bug fix"] +description = "Fixes a bug in the code" +[custom_labels."Tests"] +description = "Adds or modifies tests" +[custom_labels."Bug fix with tests"] +description = "Fixes a bug in the code and adds or modifies tests" +[custom_labels."Refactoring"] +description = "Refactors the code without changing its functionality" +[custom_labels."Enhancement"] +description = "Adds new features or functionality" +[custom_labels."Documentation"] +description = "Adds or modifies documentation" +[custom_labels."SQL modifications"] +description = "Adds or modifies SQL queries" +[custom_labels."Other"] +description = "Other changes that do not fit in any of the above categories" + +#custom_labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other'] [pr_questions] # /ask # diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 1c018959..14f66532 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -19,6 +19,7 @@ PR Title: description: an informative title for the PR, describing its main theme PR Type: type: array + description: One or more labels that describe the PR type. Don't output the description in the parentheses. items: type: string enum: diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 2c710aa0..c54b5131 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -7,7 +7,7 @@ from jinja2 import Environment, StrictUndefined from pr_agent.algo.ai_handler import AiHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import load_yaml +from pr_agent.algo.utils import load_yaml, set_custom_labels from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider from pr_agent.git_providers.git_provider import get_main_pr_language @@ -44,7 +44,6 @@ class PRDescription: "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), "custom_labels": "" - } self.user_description = self.git_provider.get_user_description() @@ -142,7 +141,7 @@ class PRDescription: variables["diff"] = self.patches_diff # update diff environment = Environment(undefined=StrictUndefined) - await self.set_custom_labels(variables) + await set_custom_labels(variables) system_prompt = environment.from_string(get_settings().pr_description_prompt.system).render(variables) user_prompt = environment.from_string(get_settings().pr_description_prompt.user).render(variables) @@ -159,15 +158,6 @@ class PRDescription: return response - async def set_custom_labels(self, variables): - labels = get_settings().pr_description.custom_labels - if not labels: - # set default labels - labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other'] - labels_list = "\n - ".join(labels) if labels else "" - labels_list = f" - {labels_list}" if labels_list else "" - variables["custom_labels"] = labels_list - def _prepare_data(self): # Load the AI prediction data into a dictionary self.data = load_yaml(self.prediction.strip()) diff --git a/pr_agent/tools/pr_reviewer.py b/pr_agent/tools/pr_reviewer.py index f2ecc09b..7c722df0 100644 --- a/pr_agent/tools/pr_reviewer.py +++ b/pr_agent/tools/pr_reviewer.py @@ -9,7 +9,7 @@ from yaml import SafeLoader from pr_agent.algo.ai_handler import AiHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import convert_to_markdown, load_yaml, try_fix_yaml +from pr_agent.algo.utils import convert_to_markdown, load_yaml, try_fix_yaml, set_custom_labels from pr_agent.config_loader import get_settings from pr_agent.git_providers import get_git_provider from pr_agent.git_providers.git_provider import IncrementalPR, get_main_pr_language @@ -150,7 +150,7 @@ class PRReviewer: variables["diff"] = self.patches_diff # update diff environment = Environment(undefined=StrictUndefined) - await self.set_custom_labels(variables) + await 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) @@ -313,12 +313,3 @@ class PRReviewer: break return question_str, answer_str - - async def set_custom_labels(self, variables): - labels = get_settings().pr_description.custom_labels - if not labels: - # set default labels - labels = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', 'Other'] - labels_list = "\n - ".join(labels) if labels else "" - labels_list = f" - {labels_list}" if labels_list else "" - variables["custom_labels"] = labels_list \ No newline at end of file