Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Implement label case conversion and update label descriptions in settings files #530

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Dec 18, 2023

User description

Type

Enhancement


Description

This PR introduces a new feature that allows for label case conversion and updates label descriptions in settings files. The main changes include:

  • Added a counter and a dictionary to map minimal labels to original labels in the set_custom_labels function in pr_agent/algo/utils.py.
  • Updated the _get_prediction function in pr_agent/tools/pr_description.py and pr_agent/tools/pr_generate_labels.py to set the variables attribute.
  • Added a block of code in the _prepare_labels function in pr_agent/tools/pr_description.py and pr_agent/tools/pr_generate_labels.py to convert lowercase labels to their original case.
  • Updated the description of the labels field in pr_agent/settings/pr_custom_labels.toml and pr_agent/settings/pr_description_prompts.toml.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
3 files
utils.py                                                                                                       
    pr_agent/algo/utils.py

    Added a counter and a dictionary to map minimal labels to
    original labels in the `set_custom_labels` function.
+8/-2
pr_description.py                                                                                     
    pr_agent/tools/pr_description.py

    Updated the `_get_prediction` function to set the
    `variables` attribute and added a block of code in the
    `_prepare_labels` function to convert lowercase labels to
    their original case.
+11/-0
pr_generate_labels.py                                                                             
    pr_agent/tools/pr_generate_labels.py

    Updated the `_get_prediction` function to set the
    `variables` attribute and added a block of code in the
    `_prepare_labels` function to convert lowercase labels to
    their original case.
+11/-0
Configuration changes
2 files
pr_custom_labels.toml                                                                             
    pr_agent/settings/pr_custom_labels.toml

    Updated the description of the `labels` field.
+1/-1
pr_description_prompts.toml                                                                 
    pr_agent/settings/pr_description_prompts.toml

    Updated the description of the `labels` field.
+6/-3

Type

Enhancement


Description

  • Enhanced label handling in set_custom_labels by adding a counter and a mapping dictionary.
  • Implemented label case conversion in PR description and label generation tools to maintain label case integrity.
  • Updated descriptions in TOML settings files to improve clarity and usage understanding of label fields.

Changes walkthrough

Relevant files
Enhancement
utils.py
Enhance label handling in set_custom_labels function         

pr_agent/algo/utils.py

  • Added a counter to track the number of labels processed.
  • Created a dictionary to map minimal labels to their original labels.
  • Modified the label description assignment to use a more complex
    expression.
  • +8/-2     
    pr_description.py
    Update label handling and case conversion in PR description tool

    pr_agent/tools/pr_description.py

  • Set the variables attribute after setting custom labels.
  • Added code to convert lowercase labels to their original case using a
    dictionary.
  • +11/-0   
    pr_generate_labels.py
    Update label handling and case conversion in PR label generation tool

    pr_agent/tools/pr_generate_labels.py

  • Set the variables attribute after setting custom labels.
  • Added error handling for label case conversion.
  • +11/-0   
    Configuration changes
    pr_custom_labels.toml
    Update label field description in custom labels settings 

    pr_agent/settings/pr_custom_labels.toml

  • Updated the description of the labels field to clarify the usage of
    label keys and meanings.
  • +1/-1     
    pr_description_prompts.toml
    Update label field description in description prompts settings

    pr_agent/settings/pr_description_prompts.toml

  • Updated the description of the labels field to enhance clarity on
    label usage.
  • +6/-3     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @mrT23 mrT23 requested a review from hussam789 December 18, 2023 10:29
    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Dec 18, 2023

    /describe

    Copy link
    Contributor

    PR Analysis

    • 🎯 Main theme: Implementing label case conversion and updating label descriptions in settings files
    • 📝 PR summary: This PR introduces a feature that converts label cases and updates label descriptions in settings files. It also includes error handling for label conversion and updates to the PR description and custom labels prompts.
    • 📌 Type of PR: Enhancement
    • 🧪 Relevant tests added: No
    • ⏱️ Estimated effort to review [1-5]: 3, because the PR includes changes in multiple files and introduces new logic for label case conversion, but the changes are straightforward and well-structured.
    • 🔒 Security concerns: No

    PR Feedback

    • 💡 General suggestions: The PR is well-structured and the changes are clear. However, it would be beneficial to include unit tests for the new functionality to ensure it works as expected and prevent potential regressions in the future. Additionally, consider handling exceptions more specifically rather than catching a general Exception.

    • 🤖 Code feedback:
      relevant filepr_agent/algo/utils.py
      suggestion      Consider using a more pythonic way to iterate over the labels. Instead of using a counter, you can use enumerate. This will make the code cleaner and more readable. [medium]
      relevant linecounter = 0

      relevant filepr_agent/tools/pr_description.py
      suggestion      It would be better to use a more specific exception instead of a general Exception. This will help in identifying the exact issue if an error occurs. [important]
      relevant lineexcept Exception as e:

      relevant filepr_agent/tools/pr_generate_labels.py
      suggestion      Similar to the previous suggestion, consider using a more specific exception instead of a general Exception. [important]
      relevant lineexcept Exception as e:

      relevant filepr_agent/settings/pr_custom_labels.toml
      suggestion      The description of the 'labels' field has been updated. Make sure this change is reflected in the documentation or any other place where this field is referenced. [medium]
      relevant linelabels: List[Label] = Field(min_items=0, description="choose the relevant custom labels that describe the PR content, and return their keys. Use the value field of the Label object to better understand the label meaning.")

    How to use

    Instructions

    To invoke the PR-Agent, add a comment using one of the following commands:
    /review: Request a review of your Pull Request.
    /describe: Update the PR title and description based on the contents of the PR.
    /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    /ask <QUESTION>: Ask a question about the PR.
    /update_changelog: Update the changelog based on the PR's contents.
    /add_docs: Generate docstring for new components introduced in the PR.
    /generate_labels: Generate labels for the PR based on the PR's contents.
    see the tools guide for more details.

    To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
    For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
    To list the possible configuration parameters, add a /config comment.

    @github-actions github-actions bot changed the title feat: Implement label case conversion and update label descriptions i… Enhancement: Implement label case conversion and update label descriptions in settings files Dec 18, 2023
    @github-actions github-actions bot added the enhancement New feature or request label Dec 18, 2023
    @mrT23 mrT23 merged commit d2aef95 into main Dec 18, 2023
    5 checks passed
    @mrT23 mrT23 deleted the tr/labels branch December 18, 2023 11:21
    @Codium-ai Codium-ai deleted a comment from github-actions bot Dec 24, 2023
    @Codium-ai Codium-ai deleted a comment from github-actions bot Dec 24, 2023
    @mrT23
    Copy link
    Collaborator Author

    mrT23 commented Dec 24, 2023

    PR Code Suggestions

    💡 Suggestion:

    Use a dictionary comprehension to create labels_minimal_to_labels_dict instead of a for loop for better readability and performance.

    File: pr_agent/algo/utils.py (382-389)

    Example code:

    Existing code:

    counter = 0
    labels_minimal_to_labels_dict = {}
    for k, v in labels.items():
        description = "'" + v['description'].strip('\n').replace('\n', '\\n') + "'"
        variables["custom_labels_class"] += f"\n    {k.lower().replace(' ', '_')} = {description}"
        labels_minimal_to_labels_dict[k.lower().replace(' ', '_')] = k
        counter += 1
    variables["labels_minimal_to_labels_dict"] = labels_minimal_to_labels_dict

    Improved code:

    labels_minimal_to_labels_dict = {k.lower().replace(' ', '_'): k for k in labels.keys()}
    for k, v in labels.items():
        description = "'" + v['description'].strip('\n').replace('\n', '\\n') + "'"
        variables["custom_labels_class"] += f"\n    {k.lower().replace(' ', '_')} = {description}"
    variables["labels_minimal_to_labels_dict"] = labels_minimal_to_labels_dict

    💡 Suggestion:

    Use list comprehension to convert lowercase labels to original case for better readability and performance.

    File: pr_agent/tools/pr_description.py (209-216)

    Example code:

    Existing code:

    try:
        if "labels_minimal_to_labels_dict" in self.variables:
            d: dict = self.variables["labels_minimal_to_labels_dict"]
            for i, label_i in enumerate(pr_types):
                if label_i in d:
                    pr_types[i] = d[label_i]
    except Exception as e:
        get_logger().error(f"Error converting labels to original case {self.pr_id}: {e}")

    Improved code:

    try:
        if "labels_minimal_to_labels_dict" in self.variables:
            d: dict = self.variables["labels_minimal_to_labels_dict"]
            pr_types = [d[label_i] if label_i in d else label_i for label_i in pr_types]
    except Exception as e:
        get_logger().error(f"Error converting labels to original case {self.pr_id}: {e}")

    💡 Suggestion:

    Use list comprehension to convert lowercase labels to original case for better readability and performance.

    File: pr_agent/tools/pr_generate_labels.py (175-182)

    Example code:

    Existing code:

    try:
        if "labels_minimal_to_labels_dict" in self.variables:
            d: dict = self.variables["labels_minimal_to_labels_dict"]
            for i, label_i in enumerate(pr_types):
                if label_i in d:
                    pr_types[i] = d[label_i]
    except Exception as e:
        get_logger().error(f"Error converting labels to original case {self.pr_id}: {e}")

    Improved code:

    try:
        if "labels_minimal_to_labels_dict" in self.variables:
            d: dict = self.variables["labels_minimal_to_labels_dict"]
            pr_types = [d[label_i] if label_i in d else label_i for label_i in pr_types]
    except Exception as e:
        get_logger().error(f"Error converting labels to original case {self.pr_id}: {e}")

    Copy link
    Contributor

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Hagai comment:
    enable to write the walkthrough for this file directly here

    Copy link
    Contributor

    @barnett-yuxiang barnett-yuxiang left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    LGTM

    yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
    Enhancement: Implement label case conversion and update label descriptions in settings files
    @scorpiolin
    Copy link

    /describe

    Copy link
    Contributor

    PR Description updated to latest commit (1c4e643)

    Copy link

    @scorpiolin scorpiolin left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    test

    @atulgawand
    Copy link

    /describe

    Copy link
    Contributor

    PR Description updated to latest commit (1c4e643)

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    6 participants