in jbi/bugzilla/models.py [0:0]
def extract_from_see_also(self, project_key):
"""Extract Jira Issue Key from see_also if jira url present"""
if not self.see_also or len(self.see_also) == 0:
return None
candidates = []
for url in self.see_also:
try:
parsed_url: ParseResult = urlparse(url=url)
host_parts = parsed_url.hostname.split(".")
except (ValueError, AttributeError):
logger.info(
"Bug %s `see_also` is not a URL: %s",
self.id,
url,
extra={
"bug": {
"id": self.id,
}
},
)
continue
if any(part in JIRA_HOSTNAMES for part in host_parts):
parsed_jira_key = parsed_url.path.rstrip("/").split("/")[-1]
if parsed_jira_key: # URL ending with /
# Issue keys are like `{project_key}-{number}`
if parsed_jira_key.startswith(f"{project_key}-"):
return parsed_jira_key
# If not obvious, then keep this link as candidate.
candidates.append(parsed_jira_key)
return candidates[0] if candidates else None