Skip to content

Commit f215f20

Browse files
feat(infra): Add IAM support for Redis (#5267)
* feat: JIRA support for custom JQL filter (#5164) * jira jql support * jira jql fixes * Address comment --------- Co-authored-by: sktbcpraha <131408565+sktbcpraha@users.noreply.github.com>
1 parent 2dc564c commit f215f20

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

backend/onyx/connectors/jira/connector.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ def _perform_jql_search(
8484
f"Fetching Jira issues with JQL: {jql}, "
8585
f"starting at {start}, max results: {max_results}"
8686
)
87-
issues = jira_client.search_issues(
87+
88+
# Use custom search method to handle Atlassian's API breaking change
89+
# The old /rest/api/{version}/search endpoint has been deprecated
90+
# New endpoint is /rest/api/{version}/search/jql
91+
issues = _custom_search_issues(
92+
jira_client,
8893
jql_str=jql,
8994
startAt=start,
9095
maxResults=max_results,
@@ -98,6 +103,67 @@ def _perform_jql_search(
98103
raise RuntimeError(f"Found Jira object not of type Issue: {issue}")
99104

100105

106+
def _custom_search_issues(
107+
jira_client: JIRA,
108+
jql_str: str,
109+
startAt: int = 0,
110+
maxResults: int = 50,
111+
fields: str | None = None,
112+
) -> Iterable[Issue]:
113+
"""
114+
Simple fix for Atlassian's API breaking change.
115+
116+
The old /rest/api/{version}/search endpoint has been deprecated and removed.
117+
New endpoint is /rest/api/{version}/search/jql
118+
119+
This is a minimal fix to resolve the immediate issue. For performance improvements,
120+
see the upgrade instructions in JIRA_API_FIX_SUMMARY.md
121+
"""
122+
if isinstance(fields, str):
123+
fields = fields.split(",")
124+
elif fields is None:
125+
fields = ["*all"]
126+
127+
# Build search parameters - keep the same interface for backwards compatibility
128+
search_params = {
129+
"jql": jql_str,
130+
"startAt": startAt,
131+
"maxResults": maxResults,
132+
"fields": fields,
133+
"validateQuery": True,
134+
}
135+
136+
# Use the new JQL endpoint
137+
url = f"{jira_client.server_url}/rest/api/{jira_client._options.get('rest_api_version', '3')}/search/jql"
138+
139+
# Make the request directly to the new endpoint
140+
response = jira_client._session.post(url, json=search_params)
141+
142+
if response.status_code == 410:
143+
# Fallback to old method if needed (though it should fail now)
144+
logger.warning("JQL endpoint returned 410, falling back to old search method")
145+
return jira_client.search_issues(
146+
jql_str=jql_str,
147+
startAt=startAt,
148+
maxResults=maxResults,
149+
fields=fields,
150+
)
151+
152+
response.raise_for_status()
153+
data = response.json()
154+
155+
# Convert the response to Issue objects
156+
issues = []
157+
for issue_data in data.get("issues", []):
158+
issue = Issue(jira_client, issue_data)
159+
# Ensure the issue has the necessary attributes
160+
if not hasattr(issue, "key") and "key" in issue_data:
161+
issue.key = issue_data["key"]
162+
issues.append(issue)
163+
164+
return issues
165+
166+
101167
def process_jira_issue(
102168
jira_client: JIRA,
103169
issue: Issue,

0 commit comments

Comments
 (0)