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 of PR Description and Labeling Features with Semantic File Types and Line Count #509

Merged
merged 15 commits into from
Dec 6, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Dec 6, 2023

Type

Enhancement


Description

This PR introduces several enhancements and changes to the PR description and labeling features:

  • Removed 'Refactoring' from the list of default labels.
  • Enhanced link generation for relevant lines in Bitbucket, GitHub, and GitLab providers.
  • Added the ability to count the number of lines added and removed in a file patch.
  • Improved the formatting of help command descriptions.
  • Added the ability to include a file walkthrough and semantic file types in the PR description.
  • Updated the prompts in 'pr_description_prompts.toml' for clarity and to reflect the new features.
  • Updated the 'configuration.toml' settings to enable or disable the new PR description features.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
7 files
pr_description.py                                                                                     
    pr_agent/tools/pr_description.py

    Added the ability to include a file walkthrough and semantic
    file types in the PR description. Also, added the ability to
    count the number of lines added and removed in a file patch.
+111/-5
help.py                                                                                                         
    pr_agent/servers/help.py

    Improved the formatting of help command descriptions.
+12/-12
github_provider.py                                                                                   
    pr_agent/git_providers/github_provider.py

    Enhanced link generation for relevant lines in GitHub
    provider.
+12/-3
gitlab_provider.py                                                                                   
    pr_agent/git_providers/gitlab_provider.py

    Enhanced link generation for relevant lines in GitLab
    provider.
+12/-2
utils.py                                                                                                       
    pr_agent/algo/utils.py

    Removed 'Refactoring' from the list of default labels.
+2/-2
bitbucket_provider.py                                                                             
    pr_agent/git_providers/bitbucket_provider.py

    Enhanced link generation for relevant lines in Bitbucket
    provider.
+4/-1
git_provider.py                                                                                         
    pr_agent/git_providers/git_provider.py

    Added fields to count the number of lines added and removed
    in a file patch.
+2/-0
Configuration changes
3 files
pr_description_prompts.toml                                                                 
    pr_agent/settings/pr_description_prompts.toml

    Updated the prompts for clarity and to reflect the new
    features.
+28/-3
configuration.toml                                                                                   
    pr_agent/settings/configuration.toml

    Updated the settings to enable or disable the new PR
    description features.
+4/-1
custom_labels.toml                                                                                   
    pr_agent/settings/custom_labels.toml

    Removed 'Refactoring' from the list of custom labels.
+1/-3

Copy link
Contributor

github-actions bot commented Dec 6, 2023

PR Analysis

  • 🎯 Main theme: Refactoring of the PR Agent to enhance the PR description and labeling features.
  • 📝 PR summary: This PR introduces changes to the PR Agent, focusing on improving the PR description and labeling features. It removes the 'Refactoring' label from the custom labels, enhances the link generation for relevant lines, and refactors the semantic labels in PR descriptions. It also adds line count to file patch info and enhances PR description formatting.
  • 📌 Type of PR: Refactoring
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 4, because the PR touches multiple files and introduces several changes, including refactoring and feature enhancements. It requires a good understanding of the existing codebase to review effectively.
  • 🔒 Security concerns: No security concerns found

PR Feedback

  • 💡 General suggestions: The PR includes a good amount of refactoring and feature enhancements. However, it would be beneficial to include tests for the new features and changes introduced. This would help ensure the robustness of the code and prevent potential regressions in the future.

  • 🤖 Code feedback:
    • relevant file: pr_agent/git_providers/github_provider.py
      suggestion: Consider using a more descriptive variable name than 'p' in the 'publish_labels' method. This would improve code readability. [medium]
      relevant line: for p in pr_types:

    • relevant file: pr_agent/algo/utils.py
      suggestion: It seems like there are commented lines of code in the 'set_custom_labels' method. If these lines are not needed, consider removing them to keep the code clean. [medium]
      relevant line: #final_labels = ""

    • relevant file: pr_agent/git_providers/github_provider.py
      suggestion: In the 'get_diff_files' method, consider handling the case where the file status is not 'renamed', 'added', or 'modified'. Currently, it defaults to 'UNKNOWN', but it might be beneficial to log or handle this case explicitly. [important]
      relevant line: else:

    • relevant file: pr_agent/tools/pr_description.py
      suggestion: In the '_prepare_pr_answer' method, consider handling the case where 'key' is not 'pr_files' or contains 'walkthrough'. Currently, it defaults to a generic handling, but it might be beneficial to handle this case explicitly. [medium]
      relevant line: else:

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.

Copy link
Contributor

github-actions bot commented Dec 6, 2023

PR Code Suggestions

💡 Suggestion:

Avoid using pass in the except block. Instead, consider logging the error message to help with debugging.

File: pr_agent/tools/pr_description.py (335-346)

Example code:

Existing code:

try:
    filename = file['filename'].replace("'", "`").replace('"', '`')
    changes_summary = file['changes_summary']
    label = file['label']
    if label not in self.file_label_dict:
        self.file_label_dict[label] = []
    self.file_label_dict[label].append((filename, changes_summary))
except Exception as e:
    get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")
    pass

Improved code:

try:
    filename = file['filename'].replace("'", "`").replace('"', '`')
    changes_summary = file['changes_summary']
    label = file['label']
    if label not in self.file_label_dict:
        self.file_label_dict[label] = []
    self.file_label_dict[label].append((filename, changes_summary))
except Exception as e:
    get_logger().error(f"Error preparing file label dict {self.pr_id}: {e}")

💡 Suggestion:

Avoid hardcoding the URL. Consider using a configuration file or environment variables to store the base URL.

File: pr_agent/git_providers/github_provider.py (514-521)

Example code:

Existing code:

if relevant_line_start == -1:
    link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}"
elif relevant_line_end:
    link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}-R{relevant_line_end}"
else:
    link = f"https://github.com/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"

Improved code:

base_url = get_settings().github_base_url
if relevant_line_start == -1:
    link = f"{base_url}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}"
elif relevant_line_end:
    link = f"{base_url}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}-R{relevant_line_end}"
else:
    link = f"{base_url}/{self.repo}/pull/{self.pr_num}/files#diff-{sha_file}R{relevant_line_start}"

💡 Suggestion:

Use a multiline string for better readability.

File: pr_agent/servers/help.py (1-11)

Example code:

Existing code:

commands_text = "> **/review**: Request a review of your Pull Request.   \n" \
                "> **/describe**: Update the PR title and description based on the contents of the PR.   \n" \
                "> **/improve [--extended]**: Suggest code improvements. Extended mode provides a higher quality feedback.   \n" \
                "> **/ask \\<QUESTION\\>**: Ask a question about the PR.   \n" \
                "> **/update_changelog**: Update the changelog based on the PR's contents.   \n" \
                "> **/add_docs**: Generate docstring for new components introduced in the PR.   \n" \
                "> **/generate_labels**: Generate labels for the PR based on the PR's contents.   \n" \
                "> see the [tools guide](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md) for more details.\n\n" \
                ">To edit any configuration parameter from the [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml), add --config_path=new_value.  \n" \
                ">For example: /review --pr_reviewer.extra_instructions=\"focus on the file: ...\"    \n" \
                ">To list the possible configuration parameters, add a **/config** comment.   \n"

Improved code:

commands_text = """
> **/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](https://github.com/Codium-ai/pr-agent/blob/main/docs/TOOLS_GUIDE.md) for more details.
>To edit any configuration parameter from the [configuration.toml](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/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.
"""

💡 Suggestion:

Use a more descriptive name for the configuration parameter.

File: pr_agent/settings/configuration.toml (49-50)

Example code:

Existing code:

enable_file_walkthrough=false
enable_semantic_files_types=true

Improved code:

enable_file_changes_walkthrough=false
enable_semantic_file_change_types=true

@mrT23 mrT23 changed the title Trlabeling files extended Enhancement of PR Description and Labeling Features Dec 6, 2023
@mrT23 mrT23 added the enhancement New feature or request label Dec 6, 2023
@mrT23 mrT23 merged commit 73eafa2 into main Dec 6, 2023
4 checks passed
@mrT23 mrT23 deleted the trlabeling_files_extended branch December 6, 2023 15:05
@mrT23 mrT23 changed the title Enhancement of PR Description and Labeling Features Enhancement of PR Description and Labeling Features with Semantic File Types and Line Count Dec 7, 2023
@mrT23
Copy link
Collaborator Author

mrT23 commented Dec 7, 2023

/describe

Copy link
Contributor

github-actions bot commented Dec 7, 2023

PR Description updated to latest commit (a61e492)

yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
…nded

Enhancement of PR Description and Labeling Features
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.

2 participants