Skip to content

Commit

Permalink
Fix content extraction from JIRA with API v2 vs. v3
Browse files Browse the repository at this point in the history
  • Loading branch information
artmatsak committed Jun 21, 2024
1 parent b07fdbf commit bdb5c12
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions backend/danswer/connectors/danswer_jira/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ def extract_jira_project(url: str) -> tuple[str, str]:
return jira_base, jira_project


def extract_text_from_content(content: dict) -> str:
def extract_text_from_adf(adf: dict | None) -> str:
"""Extracts plain text from Atlassian Document Format:
https://developer.atlassian.com/cloud/jira/platform/apis/document/structure/
WARNING: This function is incomplete and will e.g. skip lists!
"""
texts = []
if "content" in content:
for block in content["content"]:
if adf is not None and "content" in adf:
for block in adf["content"]:
if "content" in block:
for item in block["content"]:
if item["type"] == "text":
Expand All @@ -62,15 +67,8 @@ def _get_comment_strs(
comment_strs = []
for comment in jira.fields.comment.comments:
try:
if hasattr(comment, "body"):
body_text = extract_text_from_content(comment.raw["body"])
elif hasattr(comment, "raw"):
body = comment.raw.get("body", "No body content available")
body_text = (
extract_text_from_content(body) if isinstance(body, dict) else body
)
else:
body_text = "No body attribute found"
body_text = (comment.body if JIRA_API_VERSION == "2"
else extract_text_from_adf(comment.raw["body"]))

if (
hasattr(comment, "author")
Expand Down Expand Up @@ -116,9 +114,11 @@ def fetch_jira_issues_batch(
)
continue

description = (jira.fields.description if JIRA_API_VERSION == "2"
else extract_text_from_adf(jira.raw["fields"]["description"]))
comments = _get_comment_strs(jira, comment_email_blacklist)
semantic_rep = f"{jira.fields.description}\n" + "\n".join(
[f"Comment: {comment}" for comment in comments]
semantic_rep = f"{description}\n" + "\n".join(
[f"Comment: {comment}" for comment in comments if comment]
)

page_url = f"{jira_client.client_info()}/browse/{jira.key}"
Expand Down

0 comments on commit bdb5c12

Please sign in to comment.