Skip to content

Commit

Permalink
Fix get_user_description
Browse files Browse the repository at this point in the history
The headers changed from "PR Type"/"PR Description"/etc to "Type"/"Description"/etc
  • Loading branch information
zmeir committed Jan 3, 2024
1 parent c31ce3d commit 560d30d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pr_agent/git_providers/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ def get_pr_description(self, *, full: bool = True) -> str:
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):
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/tools/pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def _prepare_pr_answer(self) -> Tuple[str, str]:
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"):
Expand Down

0 comments on commit 560d30d

Please sign in to comment.