mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-28 21:05:17 +02:00
Fix content extraction from JIRA with API v2 vs. v3 (#1678)
This commit is contained in:
@@ -45,10 +45,15 @@ def extract_jira_project(url: str) -> tuple[str, str]:
|
|||||||
return jira_base, jira_project
|
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 = []
|
texts = []
|
||||||
if "content" in content:
|
if adf is not None and "content" in adf:
|
||||||
for block in content["content"]:
|
for block in adf["content"]:
|
||||||
if "content" in block:
|
if "content" in block:
|
||||||
for item in block["content"]:
|
for item in block["content"]:
|
||||||
if item["type"] == "text":
|
if item["type"] == "text":
|
||||||
@@ -72,15 +77,8 @@ def _get_comment_strs(
|
|||||||
comment_strs = []
|
comment_strs = []
|
||||||
for comment in jira.fields.comment.comments:
|
for comment in jira.fields.comment.comments:
|
||||||
try:
|
try:
|
||||||
if hasattr(comment, "body"):
|
body_text = (comment.body if JIRA_API_VERSION == "2"
|
||||||
body_text = extract_text_from_content(comment.raw["body"])
|
else extract_text_from_adf(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"
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
hasattr(comment, "author")
|
hasattr(comment, "author")
|
||||||
@@ -127,11 +125,11 @@ def fetch_jira_issues_batch(
|
|||||||
)
|
)
|
||||||
continue
|
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)
|
comments = _get_comment_strs(jira, comment_email_blacklist)
|
||||||
semantic_rep = (
|
semantic_rep = f"{description}\n" + "\n".join(
|
||||||
f"{jira.fields.description}\n"
|
[f"Comment: {comment}" for comment in comments if comment]
|
||||||
if jira.fields.description
|
|
||||||
else "" + "\n".join([f"Comment: {comment}" for comment in comments])
|
|
||||||
)
|
)
|
||||||
|
|
||||||
page_url = f"{jira_client.client_info()}/browse/{jira.key}"
|
page_url = f"{jira_client.client_info()}/browse/{jira.key}"
|
||||||
|
Reference in New Issue
Block a user