mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 04:10:49 +08:00
Find user description in a case-insensitive way
This commit is contained in:
@ -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):
|
||||
|
Reference in New Issue
Block a user