diff --git a/pr_agent/git_providers/git_provider.py b/pr_agent/git_providers/git_provider.py index 38b532ef..97fb0529 100644 --- a/pr_agent/git_providers/git_provider.py +++ b/pr_agent/git_providers/git_provider.py @@ -75,20 +75,33 @@ 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_lowercase): return description - # if the existing description was generated by the pr-agent, but it doesn't contain the user description, + + # if the existing description was generated by the pr-agent, but it doesn't contain a user description, # return nothing (empty string) because it means there is no user 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 - 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() + # 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() + + # the 'user description' is in the beginning. extract and return it + original_user_description = description.split("___")[0].strip() + if original_user_description.lower().startswith(user_description_header): + original_user_description = original_user_description[len(user_description_header):].strip() + return original_user_description + + 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") + possible_headers = ( + "## user description", "## 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 diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 6b6cdc9b..4d799a60 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -46,7 +46,7 @@ enable_help_text=true # Determines whether to include help text in the PR review [pr_description] # /describe # publish_labels=true publish_description_as_comment=false -add_original_user_description=false +add_original_user_description=true keep_original_user_title=false use_bullet_points=true extra_instructions = "" diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index 2741f361..858b8921 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -186,7 +186,7 @@ class PRDescription: self.data = load_yaml(self.prediction.strip()) if get_settings().pr_description.add_original_user_description and self.user_description: - self.data["User Description"] = self.user_description + "\n\n___\n\n" + self.data["User Description"] = self.user_description # re-order keys if 'User Description' in self.data: