Find user description in a case-insensitive way

This commit is contained in:
Zohar Meir
2024-01-04 09:41:55 +02:00
committed by GitHub
parent 39c1866121
commit 8d2da74380

View File

@ -74,19 +74,22 @@ class GitProvider(ABC):
def get_user_description(self) -> str:
description = (self.get_pr_description_full() or "").strip()
description_lowercase = description.lower()
# if the existing description wasn't generated by the pr-agent, just return it as-is
if not self._is_generated_by_pr_agent(description):
if not self._is_generated_by_pr_agent(description_lowercase):
return description
# if the existing description was generated by the pr-agent, but it doesn't contain the user description,
# return nothing (empty string) because it means there is no user description
if "## User Description" not in description:
user_description_header = "## user description"
if user_description_header not in description_lowercase:
return ""
# otherwise, extract the original user description from the existing pr-agent description and return it
return description.split("## User Description", 1)[-1].split("\n", 1)[-1].strip()
user_description_start_position = description_lowercase.find(user_description_header) + len(user_description_header)
return description[user_description_start_position:].split("\n", 1)[-1].strip()
def _is_generated_by_pr_agent(self, description: str) -> bool:
possible_headers = ("## PR Type", "## PR Description", "## PR Labels", "## Type", "## Description", "## Labels", "### 🤖 Generated by PR Agent")
return any(description.startswith(header) for header in possible_headers)
def _is_generated_by_pr_agent(self, description_lowercase: str) -> bool:
possible_headers = ("## pr type", "## pr description", "## pr labels", "## type", "## description", "## labels", "### 🤖 generated by pr agent")
return any(description_lowercase.startswith(header) for header in possible_headers)
@abstractmethod
def get_repo_settings(self):