Skip to content

Commit

Permalink
Merge pull request Codium-ai#561 from zmeir/zmeir/fix/get_user_descri…
Browse files Browse the repository at this point in the history
…ption

Fix `get_user_description`
  • Loading branch information
mrT23 committed Jan 4, 2024
2 parents 92f89e6 + 8d2da74 commit b7af451
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pr_agent/git_providers/git_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,22 @@ def get_pr_description(self, *, full: bool = True) -> str:

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):
Expand Down

0 comments on commit b7af451

Please sign in to comment.