diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 6a7d62cf..b4ed2b39 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -341,7 +341,7 @@ def set_custom_labels(variables): # final_labels += f" - {k} ({v['description']})\n" #variables["custom_labels"] = final_labels #variables["custom_labels_examples"] = f" - {list(labels.keys())[0]}" - variables["custom_labels_class"] = "class Labels(Enum):" + variables["custom_labels_class"] = "class Label(Enum):" for k, v in labels.items(): variables["custom_labels_class"] += f"\n {k.lower().replace(' ','_')} = '{k}' # {v['description']}" diff --git a/pr_agent/cli.py b/pr_agent/cli.py index 6728db9f..60948db5 100644 --- a/pr_agent/cli.py +++ b/pr_agent/cli.py @@ -21,18 +21,22 @@ For example: - cli.py --issue_url=... similar_issue Supported commands: --review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement. +- review / review_pr - Add a review that includes a summary of the PR and specific suggestions for improvement. --ask / ask_question [question] - Ask a question about the PR. +- ask / ask_question [question] - Ask a question about the PR. --describe / describe_pr - Modify the PR title and description based on the PR's contents. +- describe / describe_pr - Modify the PR title and description based on the PR's contents. --improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit. +- improve / improve_code - Suggest improvements to the code in the PR as pull request comments ready to commit. Extended mode ('improve --extended') employs several calls, and provides a more thorough feedback --reflect - Ask the PR author questions about the PR. +- reflect - Ask the PR author questions about the PR. --update_changelog - Update the changelog based on the PR's contents. +- update_changelog - Update the changelog based on the PR's contents. + +- add_docs + +- generate_labels Configuration: diff --git a/pr_agent/settings/pr_custom_labels.toml b/pr_agent/settings/pr_custom_labels.toml index f295798a..bcc1c1ff 100644 --- a/pr_agent/settings/pr_custom_labels.toml +++ b/pr_agent/settings/pr_custom_labels.toml @@ -11,38 +11,35 @@ Extra instructions from the user: ' {% endif %} -You must use the following YAML schema to format your answer: -```yaml -PR Type: - type: array +The output must be a YAML object equivalent to type $Labels, according to the following Pydantic definitions: +' {%- 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 }} + +{{ custom_labels_class }} + {%- else %} - - Bug fix - - Tests - - Refactoring - - Enhancement - - Documentation - - Other +class Label(Enum): + bug_fix = "Bug fix" + tests = "Tests" + refactoring = "Refactoring" + enhancement = "Enhancement" + documentation = "Documentation" + other = "Other" {%- endif %} +class Labels(BaseModel): + labels: List[Label] +' + + Example output: ```yaml -PR Type: -{%- if enable_custom_labels %} -{{ custom_labels_examples }} -{%- else %} - - Bug fix -{%- endif %} +labels: +- ... +- ... ``` -Make sure to output a valid YAML. Don't repeat the prompt in the answer, and avoid outputting the 'type' and 'description' fields. +Answer should be a valid YAML, and nothing else. """ user="""PR Info: diff --git a/pr_agent/settings/pr_description_prompts.toml b/pr_agent/settings/pr_description_prompts.toml index 9b2cf861..bace848e 100644 --- a/pr_agent/settings/pr_description_prompts.toml +++ b/pr_agent/settings/pr_description_prompts.toml @@ -38,7 +38,7 @@ Class PRDescription(BaseModel): type: List[PRType] = Field(description="one or more types that describe the PR type") description: str = Field(description="an informative and concise description of the PR. {%- if use_bullet_points %} Use bullet points. {% endif %}") {%- if enable_custom_labels %} - labels: List[Labels] = Field(description="one or more custom labels that describe the PR") + labels: List[Label] = Field(description="one or more custom labels that describe the PR") {%- endif %} main_files_walkthrough: List[FileWalkthrough] = Field(max_items=10) ' diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index f1757033..c0eb6606 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -44,7 +44,7 @@ class PRDescription: "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), "enable_custom_labels": get_settings().config.enable_custom_labels, - "custom_labels_class": "", # will be filled if necessary in 'set_custom_labels' + "custom_labels_class": "", # will be filled if necessary in 'set_custom_labels' function } self.user_description = self.git_provider.get_user_description() diff --git a/pr_agent/tools/pr_generate_labels.py b/pr_agent/tools/pr_generate_labels.py index e413e96f..45c504b3 100644 --- a/pr_agent/tools/pr_generate_labels.py +++ b/pr_agent/tools/pr_generate_labels.py @@ -43,9 +43,8 @@ class PRGenerateLabels: "use_bullet_points": get_settings().pr_description.use_bullet_points, "extra_instructions": get_settings().pr_description.extra_instructions, "commit_messages_str": self.git_provider.get_commit_messages(), - "custom_labels": "", - "custom_labels_examples": "", "enable_custom_labels": get_settings().config.enable_custom_labels, + "custom_labels_class": "", # will be filled if necessary in 'set_custom_labels' function } # Initialize the token handler @@ -159,11 +158,11 @@ class PRGenerateLabels: def _prepare_labels(self) -> List[str]: 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 the 'labels' key is present in the dictionary, split its value by comma and assign it to 'pr_types' + if 'labels' in self.data: + if type(self.data['labels']) == list: + pr_types = self.data['labels'] + elif type(self.data['labels']) == str: + pr_types = self.data['labels'].split(',') return pr_types