This commit is contained in:
mrT23
2024-06-28 08:04:35 +03:00
parent 15f854336a
commit e5aae0d14f
2 changed files with 8 additions and 38 deletions

View File

@ -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}")

View File

@ -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