-
Notifications
You must be signed in to change notification settings - Fork 525
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
Enhancements to PR Code Suggestions Handling and Configuration #546
Conversation
…code_suggestions.py and pr_code_suggestions_prompts.toml - Update key names in pr_code_suggestions.py to use snake_case for consistency - Implement removal of invalid suggestions where existing code is equal to improved code - Update YAML parsing in _prepare_pr_code_suggestions method to include keys_fix_yaml parameter - Refactor push_inline_code_suggestions method to use updated key names - Update _prepare_prediction_extended method to use new key names - Refactor _prepare_markdown method to include suggestion label and use updated key names - Update instructions and YAML schema in pr_code_suggestions_prompts.toml to reflect changes in pr_code_suggestions.py - Remove redundant removal of invalid suggestions in rank_suggestions method
…e suggestion handling - Update `create_inline_comment` method in various git providers to include `absolute_position` parameter - Remove `create_inline_comment` method from providers that do not support inline comments - Enhance `find_line_number_of_relevant_line_in_file` function to handle absolute position - Modify `pr_code_suggestions.py` to handle improved code inclusion in suggestions - Add `include_improved_code` configuration option in `configuration.toml` and update documentation accordingly
PR Description updated to latest commit (5c49ff2) |
PR Analysis
PR Feedback
How to useInstructions
|
/add_docs |
PR DocumentationHere is a list of the files that were modified in the PR, with docstring for each altered code component:
|
/describe |
PR Description updated to latest commit (663632e) |
/improve --extended |
PR Code Suggestions💡 [error handling] Consider adding error handling for when File: pr_agent/git_providers/bitbucket_provider.py (205-210) Example code:Existing code: position, absolute_position = find_line_number_of_relevant_line_in_file(self.get_diff_files(),
relevant_file.strip('`'),
relevant_line_in_file, absolute_position)
if position == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}") Improved code: position, absolute_position = find_line_number_of_relevant_line_in_file(self.get_diff_files(),
relevant_file.strip('`'),
relevant_line_in_file, absolute_position)
if position == -1 or absolute_position == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
return 💡 [error handling] Consider adding error handling for when File: pr_agent/git_providers/github_provider.py (211-216) Example code:Existing code: position, absolute_position = find_line_number_of_relevant_line_in_file(self.diff_files,
relevant_file.strip('`'),
relevant_line_in_file,
absolute_position)
if position == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}") Improved code: position, absolute_position = find_line_number_of_relevant_line_in_file(self.diff_files,
relevant_file.strip('`'),
relevant_line_in_file,
absolute_position)
if position == -1 or absolute_position == -1:
if get_settings().config.verbosity_level >= 2:
get_logger().info(f"Could not find position for {relevant_file} {relevant_line_in_file}")
return 💡 [maintainability] Consider refactoring the code to avoid deep nesting. Deeply nested code can be difficult to read and understand. File: pr_agent/algo/pr_processing.py (275-290) Example code:Existing code: for file in diff_files:
if file.filename and (file.filename.strip() == relevant_file):
patch = file.patch
patch_lines = patch.splitlines()
delta = 0
start1, size1, start2, size2 = 0, 0, 0, 0
if absolute_position != -1: # matching absolute to relative
for i, line in enumerate(patch_lines):
# new hunk
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1 Improved code: for file in diff_files:
if not file.filename or file.filename.strip() != relevant_file:
continue
patch = file.patch
patch_lines = patch.splitlines()
line_difference = 0
start1, size1, start2, size2 = 0, 0, 0, 0
if absolute_position != -1: # matching absolute to relative
for i, line in enumerate(patch_lines):
# new hunk
if line.startswith('@@'):
line_difference = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
line_difference += 1 💡 [best practice] Instead of checking if a key exists in a dictionary and then extending it, you can use File: pr_agent/tools/pr_code_suggestions.py (227-230) Example code:Existing code: if "code_suggestions" in data:
data["code_suggestions"].extend(data_per_chunk["code_suggestions"])
else:
data.update(data_per_chunk) Improved code: data.setdefault("code_suggestions", []).extend(data_per_chunk["code_suggestions"]) 💡 [best practice] It's a good practice to use list comprehensions for creating a new list from an existing one. It's more readable and usually faster. File: pr_agent/tools/pr_code_suggestions.py (246-247) Example code:Existing code: suggestion_list = []
for suggestion in data:
suggestion_list.append(suggestion) Improved code: suggestion_list = [suggestion for suggestion in data] 💡 [maintainability] Consider using a more descriptive variable name than File: pr_agent/algo/pr_processing.py (279-280) Example code:Existing code: delta = 0
start1, size1, start2, size2 = 0, 0, 0, 0 Improved code: line_difference = 0
start1, size1, start2, size2 = 0, 0, 0, 0 💡 [maintainability] Consider using a more descriptive variable name than File: pr_agent/algo/pr_processing.py (282-289) Example code:Existing code: for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1 Improved code: for line_index, line in enumerate(patch_lines):
if line.startswith('@@'):
line_difference = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
line_difference += 1 💡 [maintainability] Consider using a more descriptive variable name than File: pr_agent/algo/pr_processing.py (305-311) Example code:Existing code: for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1 Improved code: for line_index, line in enumerate(patch_lines):
if line.startswith('@@'):
line_difference = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
line_difference += 1 💡 [maintainability] Consider using a more descriptive variable name than File: pr_agent/algo/pr_processing.py (320-326) Example code:Existing code: for i, line in enumerate(patch_lines):
if line.startswith('@@'):
delta = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
delta += 1 Improved code: for line_index, line in enumerate(patch_lines):
if line.startswith('@@'):
line_difference = 0
match = re_hunk_header.match(line)
start1, size1, start2, size2 = map(int, match.groups()[:4])
elif not line.startswith('-'):
line_difference += 1 💡 [enhancement] It's a good practice to use File: pr_agent/tools/pr_code_suggestions.py (310-311) Example code:Existing code: data_markdown += f"Existing code:\n```{language_name}\n{s['existing_code'].rstrip()}\n```\n"
data_markdown += f"Improved code:\n```{language_name}\n{s['improved_code'].rstrip()}\n```\n" Improved code: data_markdown += f"Existing code:\n```{language_name}\n{s['existing_code'].rstrip(' \n')}\n```\n"
data_markdown += f"Improved code:\n```{language_name}\n{s['improved_code'].rstrip(' \n')}\n```\n" 💡 [enhancement] Instead of using File: pr_agent/tools/pr_code_suggestions.py (310-311) Example code:Existing code: data_markdown += f"Existing code:\n```{language_name}\n{s['existing_code'].rstrip()}\n```\n"
data_markdown += f"Improved code:\n```{language_name}\n{s['improved_code'].rstrip()}\n```\n" Improved code: data_markdown += f"Existing code:\n```{language_name}\n{s['existing_code'].rstrip(' \n')}\n```\n"
data_markdown += f"Improved code:\n```{language_name}\n{s['improved_code'].rstrip(' \n')}\n```\n" 💡 [enhancement] It's a good practice to use File: pr_agent/tools/pr_code_suggestions.py (299-299) Example code:Existing code: data_markdown += f"\n💡 [{label}]\n\n**{s['suggestion_content'].rstrip().rstrip()}**\n\n" Improved code: data_markdown += f"\n💡 [{label}]\n\n**{s['suggestion_content'].rstrip()}**\n\n" 💡 [enhancement] Instead of using File: pr_agent/tools/pr_code_suggestions.py (299-299) Example code:Existing code: data_markdown += f"\n💡 [{label}]\n\n**{s['suggestion_content'].rstrip().rstrip()}**\n\n" Improved code: data_markdown += f"\n💡 [{label}]\n\n**{s['suggestion_content'].rstrip(' \n')}**\n\n" 💡 [enhancement] Consider using a more pythonic way to check if a key exists in a dictionary. Instead of File: pr_agent/tools/pr_code_suggestions.py (68-70) Example code:Existing code: if (not data) or (not 'code_suggestions' in data):
get_logger().info('No code suggestions found for PR.')
return Improved code: if (not data) or ('code_suggestions' not in data):
get_logger().info('No code suggestions found for PR.')
return |
Single-label for suggestions
Type
Enhancement
Description
This PR introduces several enhancements to the PR code suggestions handling and configuration:
pr_code_suggestions.py
for consistency and improved functionality._prepare_pr_code_suggestions
method to includekeys_fix_yaml
parameter.absolute_position
parameter.find_line_number_of_relevant_line_in_file
function to handle absolute position.include_improved_code
configuration option inconfiguration.toml
and updated the documentation accordingly.PR changes walkthrough
7 files
pr_code_suggestions.py
pr_agent/tools/pr_code_suggestions.py
- Updating the YAML parsing in
- Adding functionality to remove
- Updating the inline comment creation to include the
- Enhancing the
- Adding the
**This file has undergone significant changes to improve the
handling of code suggestions. The changes include:
Refactoring of the code suggestion handling for consistency
and improved functionality.
the
_prepare_pr_code_suggestions
method to include thekeys_fix_yaml
parameter.invalid suggestions where existing code is equal to improved
code.
absolute_position
parameter.find_line_number_of_relevant_line_in_file
function tohandle absolute position.
include_improved_code
configuration option.**pr_processing.py
pr_agent/algo/pr_processing.py
The
find_line_number_of_relevant_line_in_file
function hasbeen enhanced to handle absolute position.
github_provider.py
pr_agent/git_providers/github_provider.py
The
create_inline_comment
method has been updated toinclude the
absolute_position
parameter.bitbucket_provider.py
pr_agent/git_providers/bitbucket_provider.py
The
create_inline_comment
method has been updated toinclude the
absolute_position
parameter.gitlab_provider.py
pr_agent/git_providers/gitlab_provider.py
The
create_inline_comment
method has been updated toinclude the
absolute_position
parameter.bitbucket_server_provider.py
pr_agent/git_providers/bitbucket_server_provider.py
The
create_inline_comment
method has been updated toinclude the
absolute_position
parameter.git_provider.py
pr_agent/git_providers/git_provider.py
The
create_inline_comment
method has been updated toinclude the
absolute_position
parameter.2 files
pr_code_suggestions_prompts.toml
pr_agent/settings/pr_code_suggestions_prompts.toml
The instructions and YAML schema have been updated to
reflect changes in
pr_code_suggestions.py
.IMPROVE.md
docs/IMPROVE.md
The documentation has been updated to include the
include_improved_code
configuration option.1 files
configuration.toml
pr_agent/settings/configuration.toml
The
include_improved_code
configuration option has beenadded.