From 560d30dbb1d54cbf5ab641808786c67b9f0b09a4 Mon Sep 17 00:00:00 2001 From: zmeir Date: Wed, 3 Jan 2024 09:56:23 +0200 Subject: [PATCH 1/3] Fix `get_user_description` The headers changed from "PR Type"/"PR Description"/etc to "Type"/"Description"/etc --- pr_agent/git_providers/git_provider.py | 10 +++++++--- pr_agent/tools/pr_description.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index b2d31322..036887e5 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -75,14 +75,18 @@ class GitProvider(ABC): def get_user_description(self) -> str: description = (self.get_pr_description_full() or "").strip() # 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): 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: + if "## User Description" not in description: return "" # otherwise, extract the original user description from the existing pr-agent description and return it - return description.split("## User Description:", 1)[1].strip() + return description.split("## User Description", 1)[-1].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) @abstractmethod def get_repo_settings(self): diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index d79c2d50..2e3c465e 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -297,7 +297,7 @@ class PRDescription: value = self.file_label_dict key_publish = "PR changes walkthrough" else: - key_publish = key.rstrip(':').replace("_", " ").capitalize() + key_publish = key.rstrip(':').replace("_", " ").title() pr_body += f"## {key_publish}\n" if 'walkthrough' in key.lower(): if self.git_provider.is_supported("gfm_markdown"): From 39c1866121677ead6eaa5b17165e225619bf74ff Mon Sep 17 00:00:00 2001 From: Zohar Meir <33152084+zmeir@users.noreply.github.com> Date: Thu, 4 Jan 2024 09:41:24 +0200 Subject: [PATCH 2/3] Revert title() to capitalize() --- pr_agent/tools/pr_description.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 2e3c465e..d79c2d50 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -297,7 +297,7 @@ class PRDescription: value = self.file_label_dict key_publish = "PR changes walkthrough" else: - key_publish = key.rstrip(':').replace("_", " ").title() + key_publish = key.rstrip(':').replace("_", " ").capitalize() pr_body += f"## {key_publish}\n" if 'walkthrough' in key.lower(): if self.git_provider.is_supported("gfm_markdown"): From 8d2da74380dd4154f44fd2dde262f52c5b41cb80 Mon Sep 17 00:00:00 2001 From: Zohar Meir <33152084+zmeir@users.noreply.github.com> Date: Thu, 4 Jan 2024 09:41:55 +0200 Subject: [PATCH 3/3] Find user description in a case-insensitive way --- pr_agent/git_providers/git_provider.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 036887e5..38b532ef 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -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):