Merge pull request #561 from zmeir/zmeir/fix/get_user_description

Fix `get_user_description`
This commit is contained in:
Tal
2024-01-04 00:40:08 -08:00
committed by GitHub

View File

@ -74,15 +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 any(description.startswith(header) for header in ("## PR Type", "## PR 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].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_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):