mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-12 02:45:18 +00:00
Fix: decouple inline and table suggestion filtering logic
- **Refactor `run` method in `PRCodeSuggestions`**: - Pre-filter suggestions based on `suggestions_score_threshold` early in the process to prevent publishing low-score suggestions in any mode. - Separate inline and table publishing logic for better clarity and control. - Ensure dual publishing mode correctly displays all valid suggestions inline while filtering the summary table based on `dual_publishing_score_threshold`. - Fix potential issue where the progress bar or "no suggestions" message could be mishandled when no high-score suggestions exist for the table. - **Update `push_inline_code_suggestions`**: - Re-verify score threshold within the function to ensure robust filtering (though pre-filtering in `run` handles this primarily now).
This commit is contained in:
parent
ab808fd114
commit
1315fa651b
1 changed files with 63 additions and 40 deletions
|
|
@ -123,59 +123,82 @@ class PRCodeSuggestions:
|
||||||
await self.publish_no_suggestions()
|
await self.publish_no_suggestions()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Filter data by suggestions_score_threshold
|
||||||
|
score_threshold = max(1, int(get_settings().pr_code_suggestions.suggestions_score_threshold))
|
||||||
|
data['code_suggestions'] = [
|
||||||
|
d for d in data['code_suggestions']
|
||||||
|
if int(d.get('score', 0)) >= score_threshold
|
||||||
|
]
|
||||||
|
|
||||||
|
if not data['code_suggestions']:
|
||||||
|
await self.publish_no_suggestions()
|
||||||
|
return
|
||||||
|
|
||||||
# publish the suggestions
|
# publish the suggestions
|
||||||
if get_settings().config.publish_output:
|
if get_settings().config.publish_output:
|
||||||
# If a temporary comment was published, remove it
|
# If a temporary comment was published, remove it
|
||||||
self.git_provider.remove_initial_comment()
|
self.git_provider.remove_initial_comment()
|
||||||
|
|
||||||
# Publish table summarized suggestions
|
# Logic for Inline Suggestions
|
||||||
if ((not get_settings().pr_code_suggestions.commitable_code_suggestions) and
|
dual_threshold = int(get_settings().pr_code_suggestions.dual_publishing_score_threshold)
|
||||||
self.git_provider.is_supported("gfm_markdown")):
|
if get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0:
|
||||||
|
await self.push_inline_code_suggestions(data)
|
||||||
|
|
||||||
# generate summarized suggestions
|
# Logic for Table Suggestions
|
||||||
pr_body = self.generate_summarized_suggestions(data)
|
if self.git_provider.is_supported("gfm_markdown") and \
|
||||||
get_logger().debug(f"PR output", artifact=pr_body)
|
(not get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0):
|
||||||
|
|
||||||
# require self-review
|
data_for_table = data
|
||||||
if get_settings().pr_code_suggestions.demand_code_suggestions_self_review:
|
# dual publishing mode
|
||||||
pr_body = await self.add_self_review_text(pr_body)
|
if dual_threshold > 0:
|
||||||
|
data_for_table = {'code_suggestions': []}
|
||||||
|
for suggestion in data['code_suggestions']:
|
||||||
|
if int(suggestion.get('score', 0)) >= dual_threshold:
|
||||||
|
data_for_table['code_suggestions'].append(suggestion)
|
||||||
|
|
||||||
# add usage guide
|
if data_for_table['code_suggestions']:
|
||||||
if (get_settings().pr_code_suggestions.enable_chat_text and get_settings().config.is_auto_command
|
# generate summarized suggestions
|
||||||
and isinstance(self.git_provider, GithubProvider)):
|
pr_body = self.generate_summarized_suggestions(data_for_table)
|
||||||
pr_body += "\n\n>💡 Need additional feedback ? start a [PR chat](https://chromewebstore.google.com/detail/ephlnjeghhogofkifjloamocljapahnl) \n\n"
|
get_logger().debug(f"PR output", artifact=pr_body)
|
||||||
if get_settings().pr_code_suggestions.enable_help_text:
|
|
||||||
pr_body += "<hr>\n\n<details> <summary><strong>💡 Tool usage guide:</strong></summary><hr> \n\n"
|
|
||||||
pr_body += HelpMessage.get_improve_usage_guide()
|
|
||||||
pr_body += "\n</details>\n"
|
|
||||||
|
|
||||||
# Output the relevant configurations if enabled
|
# require self-review
|
||||||
if get_settings().get('config', {}).get('output_relevant_configurations', False):
|
if get_settings().pr_code_suggestions.demand_code_suggestions_self_review:
|
||||||
pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions')
|
pr_body = await self.add_self_review_text(pr_body)
|
||||||
|
|
||||||
# publish the PR comment
|
# add usage guide
|
||||||
if get_settings().pr_code_suggestions.persistent_comment: # true by default
|
if (get_settings().pr_code_suggestions.enable_chat_text and get_settings().config.is_auto_command
|
||||||
self.publish_persistent_comment_with_history(self.git_provider,
|
and isinstance(self.git_provider, GithubProvider)):
|
||||||
pr_body,
|
pr_body += "\n\n>💡 Need additional feedback ? start a [PR chat](https://chromewebstore.google.com/detail/ephlnjeghhogofkifjloamocljapahnl) \n\n"
|
||||||
initial_header="## PR Code Suggestions ✨",
|
if get_settings().pr_code_suggestions.enable_help_text:
|
||||||
update_header=True,
|
pr_body += "<hr>\n\n<details> <summary><strong>💡 Tool usage guide:</strong></summary><hr> \n\n"
|
||||||
name="suggestions",
|
pr_body += HelpMessage.get_improve_usage_guide()
|
||||||
final_update_message=False,
|
pr_body += "\n</details>\n"
|
||||||
max_previous_comments=get_settings().pr_code_suggestions.max_history_len,
|
|
||||||
progress_response=self.progress_response)
|
# Output the relevant configurations if enabled
|
||||||
|
if get_settings().get('config', {}).get('output_relevant_configurations', False):
|
||||||
|
pr_body += show_relevant_configurations(relevant_section='pr_code_suggestions')
|
||||||
|
|
||||||
|
# publish the PR comment
|
||||||
|
if get_settings().pr_code_suggestions.persistent_comment: # true by default
|
||||||
|
self.publish_persistent_comment_with_history(self.git_provider,
|
||||||
|
pr_body,
|
||||||
|
initial_header="## PR Code Suggestions ✨",
|
||||||
|
update_header=True,
|
||||||
|
name="suggestions",
|
||||||
|
final_update_message=False,
|
||||||
|
max_previous_comments=get_settings().pr_code_suggestions.max_history_len,
|
||||||
|
progress_response=self.progress_response)
|
||||||
|
else:
|
||||||
|
if self.progress_response:
|
||||||
|
self.git_provider.edit_comment(self.progress_response, body=pr_body)
|
||||||
|
else:
|
||||||
|
self.git_provider.publish_comment(pr_body)
|
||||||
else:
|
else:
|
||||||
if self.progress_response:
|
if self.progress_response:
|
||||||
self.git_provider.edit_comment(self.progress_response, body=pr_body)
|
self.git_provider.remove_comment(self.progress_response)
|
||||||
else:
|
|
||||||
self.git_provider.publish_comment(pr_body)
|
|
||||||
|
|
||||||
# dual publishing mode
|
|
||||||
if int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) > 0:
|
|
||||||
await self.dual_publishing(data)
|
|
||||||
else:
|
else:
|
||||||
await self.push_inline_code_suggestions(data)
|
if self.progress_response and not (get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0):
|
||||||
if self.progress_response:
|
self.git_provider.remove_comment(self.progress_response)
|
||||||
self.git_provider.remove_comment(self.progress_response)
|
|
||||||
else:
|
else:
|
||||||
get_logger().info('Code suggestions generated for PR, but not published since publish_output is False.')
|
get_logger().info('Code suggestions generated for PR, but not published since publish_output is False.')
|
||||||
pr_body = self.generate_summarized_suggestions(data)
|
pr_body = self.generate_summarized_suggestions(data)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue