From 1315fa651ba7c013bb699dd4fada2c1cd4a0a3f7 Mon Sep 17 00:00:00 2001 From: diana-jung <104146180+diana-jung@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:56:32 +0900 Subject: [PATCH] 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). --- pr_agent/tools/pr_code_suggestions.py | 103 ++++++++++++++++---------- 1 file changed, 63 insertions(+), 40 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index fcb1d0c5..17c7cc12 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -123,59 +123,82 @@ class PRCodeSuggestions: await self.publish_no_suggestions() 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 if get_settings().config.publish_output: # If a temporary comment was published, remove it self.git_provider.remove_initial_comment() - # Publish table summarized suggestions - if ((not get_settings().pr_code_suggestions.commitable_code_suggestions) and - self.git_provider.is_supported("gfm_markdown")): + # Logic for Inline Suggestions + dual_threshold = int(get_settings().pr_code_suggestions.dual_publishing_score_threshold) + if get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0: + await self.push_inline_code_suggestions(data) - # generate summarized suggestions - pr_body = self.generate_summarized_suggestions(data) - get_logger().debug(f"PR output", artifact=pr_body) + # Logic for Table Suggestions + if self.git_provider.is_supported("gfm_markdown") and \ + (not get_settings().pr_code_suggestions.commitable_code_suggestions or dual_threshold > 0): - # require self-review - if get_settings().pr_code_suggestions.demand_code_suggestions_self_review: - pr_body = await self.add_self_review_text(pr_body) + data_for_table = data + # dual publishing mode + 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 (get_settings().pr_code_suggestions.enable_chat_text and get_settings().config.is_auto_command - and isinstance(self.git_provider, GithubProvider)): - pr_body += "\n\n>💡 Need additional feedback ? start a [PR chat](https://chromewebstore.google.com/detail/ephlnjeghhogofkifjloamocljapahnl) \n\n" - if get_settings().pr_code_suggestions.enable_help_text: - pr_body += "