From 597f1c6f8391cd10d15196480eaf7addf76902ad Mon Sep 17 00:00:00 2001 From: mrT23 Date: Mon, 28 Oct 2024 08:12:56 +0200 Subject: [PATCH] Add PRDescriptionHeader enum for consistent "Changes walkthrough" usage across modules --- pr_agent/algo/utils.py | 10 ++++++++-- pr_agent/git_providers/azuredevops_provider.py | 4 ++-- pr_agent/tools/pr_description.py | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/pr_agent/algo/utils.py b/pr_agent/algo/utils.py index 98c69d00..6a23d609 100644 --- a/pr_agent/algo/utils.py +++ b/pr_agent/algo/utils.py @@ -43,6 +43,10 @@ class PRReviewHeader(str, Enum): INCREMENTAL = "## Incremental PR Reviewer Guide" +class PRDescriptionHeader(str, Enum): + CHANGES_WALKTHROUGH = "### **Changes walkthrough** 📝" + + def get_setting(key: str) -> Any: try: key = key.upper() @@ -1024,8 +1028,7 @@ def process_description(description_full: str) -> Tuple[str, List]: if not description_full: return "", [] - split_str = "### **Changes walkthrough** 📝" - description_split = description_full.split(split_str) + description_split = description_full.split(PRDescriptionHeader.CHANGES_WALKTHROUGH) base_description_str = description_split[0] changes_walkthrough_str = "" files = [] @@ -1060,6 +1063,9 @@ def process_description(description_full: str) -> Tuple[str, List]: if not res or res.lastindex != 4: pattern_back = r'
\s*(.*?)
(.*?).*?
\s*
\s*(.*?)\n\n\s*(.*?)
' res = re.search(pattern_back, file_data, re.DOTALL) + if not res or res.lastindex != 4: + pattern_back = r'
\s*(.*?)\s*
(.*?).*?
\s*
\s*(.*?)\s*-\s*(.*?)\s*
' # looking for hypen ('- ') + res = re.search(pattern_back, file_data, re.DOTALL) if res and res.lastindex == 4: short_filename = res.group(1).strip() short_summary = res.group(2).strip() diff --git a/pr_agent/git_providers/azuredevops_provider.py b/pr_agent/git_providers/azuredevops_provider.py index edcb995c..de782998 100644 --- a/pr_agent/git_providers/azuredevops_provider.py +++ b/pr_agent/git_providers/azuredevops_provider.py @@ -5,7 +5,7 @@ from urllib.parse import urlparse from ..algo.file_filter import filter_ignored from ..log import get_logger from ..algo.language_handler import is_valid_file -from ..algo.utils import clip_tokens, find_line_number_of_relevant_line_in_file, load_large_diff +from ..algo.utils import clip_tokens, find_line_number_of_relevant_line_in_file, load_large_diff, PRDescriptionHeader from ..config_loader import get_settings from .git_provider import GitProvider from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo @@ -404,7 +404,7 @@ class AzureDevopsProvider(GitProvider): pr_body = pr_body[:ind] if len(pr_body) > MAX_PR_DESCRIPTION_AZURE_LENGTH: - changes_walkthrough_text = '## **Changes walkthrough**' + changes_walkthrough_text = PRDescriptionHeader.CHANGES_WALKTHROUGH ind = pr_body.find(changes_walkthrough_text) if ind != -1: pr_body = pr_body[:ind] diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 169533a5..1d397a54 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -12,7 +12,7 @@ from pr_agent.algo.ai_handlers.litellm_ai_handler import LiteLLMAIHandler from pr_agent.algo.pr_processing import get_pr_diff, retry_with_fallback_models, get_pr_diff_multiple_patchs, \ OUTPUT_BUFFER_TOKENS_HARD_THRESHOLD from pr_agent.algo.token_handler import TokenHandler -from pr_agent.algo.utils import set_custom_labels +from pr_agent.algo.utils import set_custom_labels, PRDescriptionHeader from pr_agent.algo.utils import load_yaml, get_user_labels, ModelType, show_relevant_configurations, get_max_tokens, \ clip_tokens from pr_agent.config_loader import get_settings @@ -501,7 +501,7 @@ extra_file_yaml = pr_body += "\n" elif 'pr_files' in key.lower() and get_settings().pr_description.enable_semantic_files_types: changes_walkthrough, pr_file_changes = self.process_pr_files_prediction(changes_walkthrough, value) - changes_walkthrough = f"### **Changes walkthrough** 📝\n{changes_walkthrough}" + changes_walkthrough = f"{PRDescriptionHeader.CHANGES_WALKTHROUGH}\n{changes_walkthrough}" else: # if the value is a list, join its items by comma if isinstance(value, list):