From e5aae0d14f543074d85e937458657a4a61421897 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 28 Jun 2024 08:04:35 +0300 Subject: [PATCH 1/2] fixes --- .../git_providers/azuredevops_provider.py | 7 ++++ pr_agent/tools/pr_code_suggestions.py | 39 +------------------ 2 files changed, 8 insertions(+), 38 deletions(-) diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index e4ea67f0..1ac153d4 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -354,6 +354,11 @@ class AzureDevopsProvider(GitProvider): file, new_file_content_str, original_file_content_str, show_warning=False ).rstrip() + # count number of lines added and removed + patch_lines = patch.splitlines(keepends=True) + num_plus_lines = len([line for line in patch_lines if line.startswith('+')]) + num_minus_lines = len([line for line in patch_lines if line.startswith('-')]) + diff_files.append( FilePatchInfo( original_file_content_str, @@ -361,6 +366,8 @@ class AzureDevopsProvider(GitProvider): patch=patch, filename=file, edit_type=edit_type, + num_plus_lines=num_plus_lines, + num_minus_lines=num_minus_lines, ) ) get_logger().info(f"Invalid files: {invalid_files_names}") diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index d08c723b..f60131ec 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -11,7 +11,7 @@ from pr_agent.algo.pr_processing import get_pr_diff, get_pr_multi_diffs, retry_w from pr_agent.algo.token_handler import TokenHandler from pr_agent.algo.utils import load_yaml, replace_code_tags, ModelType, show_relevant_configurations from pr_agent.config_loader import get_settings -from pr_agent.git_providers import get_git_provider, get_git_provider_with_context +from pr_agent.git_providers import get_git_provider, get_git_provider_with_context, GithubProvider, GitLabProvider from pr_agent.git_providers.git_provider import get_main_pr_language from pr_agent.log import get_logger from pr_agent.servers.help import HelpMessage @@ -602,40 +602,3 @@ class PRCodeSuggestions: return "" return response_reflect - async def handle_apply_suggestion(self): - try: - get_logger().info('Processing "apply" suggestion...') - suggestion_number = get_settings().apply_suggestion - comment_after = get_settings().pr_code_suggestions.get('comment_after', None) - if suggestion_number is None or comment_after is None: - get_logger().error('Invalid suggestion number or comment_after') - return False - suggestions = parse_suggestions_content(comment_after) - if not suggestions: - get_logger().error('Failed to parse suggestions') - return False - suggestion = suggestions[suggestion_number] - if hasattr(self, 'main_language'): - self.git_provider.main_language = self.main_language - relevant_file = suggestion['suggestion_orig_location']['filename'] - relevant_lines_start = int(suggestion['suggestion_orig_location']['start_line']) - relevant_lines_end = int(suggestion['suggestion_orig_location']['end_line']) - content = suggestion['suggestion_summary'] - new_code_snippet = suggestion['new_code_snippet'] - label = suggestion['category'] - score = suggestion['score'] - if new_code_snippet: - new_code_snippet = self.dedent_code(relevant_file, relevant_lines_start, new_code_snippet) - body = f"**Suggestion:** {content} [{label}, importance: {score}]\n```suggestion\n" + new_code_snippet + "\n```" - original_suggestion = suggestion - code_suggestions = [({'original_suggestion': original_suggestion, - 'body': body, 'relevant_file': relevant_file, - 'relevant_lines_start': relevant_lines_start, - 'relevant_lines_end': relevant_lines_end})] - is_successful = self.git_provider.publish_code_suggestions(code_suggestions) - get_settings().set("suggestion_score", score) - get_settings().set("suggestion_label", label) - except Exception as e: - get_logger().info(f"Failed to apply suggestion, error: {e}") - is_successful = False - return is_successful From 4c444f5c9acf7eac2403f06a5994a9f9a63d98e6 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 28 Jun 2024 08:09:52 +0300 Subject: [PATCH 2/2] fixes --- pr_agent/tools/pr_code_suggestions.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pr_agent/tools/pr_code_suggestions.py b/pr_agent/tools/pr_code_suggestions.py index f60131ec..0e39a6cf 100644 --- a/pr_agent/tools/pr_code_suggestions.py +++ b/pr_agent/tools/pr_code_suggestions.py @@ -545,13 +545,6 @@ class PRCodeSuggestions: {example_code.rstrip()} """ - if (get_settings().pr_code_suggestions.apply_suggestions_checkbox and - (isinstance(self.git_provider, GithubProvider) or isinstance(self.git_provider, - GitLabProvider))): - # add a checkbox line, to create a committal suggestion from the table suggestion - if '...' not in patch: - pr_body += f"""\n- [ ] **Apply this suggestion** \n\n""" - if get_settings().pr_code_suggestions.self_reflect_on_suggestions: pr_body += f"
Suggestion importance[1-10]: {suggestion['score']}\n\n" pr_body += f"Why: {suggestion['score_why']}\n\n"