-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(jira): Fix Deprecated Jira search API issue #5308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -84,7 +84,12 @@ def _perform_jql_search( | |||||
f"Fetching Jira issues with JQL: {jql}, " | ||||||
f"starting at {start}, max results: {max_results}" | ||||||
) | ||||||
issues = jira_client.search_issues( | ||||||
|
||||||
# Use custom search method to handle Atlassian's API breaking change | ||||||
# The old /rest/api/{version}/search endpoint has been deprecated | ||||||
# New endpoint is /rest/api/{version}/search/jql | ||||||
issues = _custom_search_issues( | ||||||
jira_client, | ||||||
jql_str=jql, | ||||||
startAt=start, | ||||||
maxResults=max_results, | ||||||
|
@@ -98,6 +103,67 @@ def _perform_jql_search( | |||||
raise RuntimeError(f"Found Jira object not of type Issue: {issue}") | ||||||
|
||||||
|
||||||
def _custom_search_issues( | ||||||
jira_client: JIRA, | ||||||
jql_str: str, | ||||||
startAt: int = 0, | ||||||
maxResults: int = 50, | ||||||
fields: str | None = None, | ||||||
) -> Iterable[Issue]: | ||||||
""" | ||||||
Simple fix for Atlassian's API breaking change. | ||||||
|
||||||
The old /rest/api/{version}/search endpoint has been deprecated and removed. | ||||||
New endpoint is /rest/api/{version}/search/jql | ||||||
|
||||||
This is a minimal fix to resolve the immediate issue. For performance improvements, | ||||||
see the upgrade instructions in JIRA_API_FIX_SUMMARY.md | ||||||
""" | ||||||
if isinstance(fields, str): | ||||||
fields = fields.split(",") | ||||||
elif fields is None: | ||||||
fields = ["*all"] | ||||||
|
||||||
# Build search parameters - keep the same interface for backwards compatibility | ||||||
search_params = { | ||||||
"jql": jql_str, | ||||||
"startAt": startAt, | ||||||
"maxResults": maxResults, | ||||||
"fields": fields, | ||||||
"validateQuery": True, | ||||||
} | ||||||
|
||||||
# Use the new JQL endpoint | ||||||
url = f"{jira_client.server_url}/rest/api/{jira_client._options.get('rest_api_version', '3')}/search/jql" | ||||||
|
||||||
# Make the request directly to the new endpoint | ||||||
response = jira_client._session.post(url, json=search_params) | ||||||
|
||||||
if response.status_code == 410: | ||||||
# Fallback to old method if needed (though it should fail now) | ||||||
logger.warning("JQL endpoint returned 410, falling back to old search method") | ||||||
return jira_client.search_issues( | ||||||
jql_str=jql_str, | ||||||
startAt=startAt, | ||||||
maxResults=maxResults, | ||||||
fields=fields, | ||||||
) | ||||||
|
||||||
response.raise_for_status() | ||||||
data = response.json() | ||||||
|
||||||
# Convert the response to Issue objects | ||||||
issues = [] | ||||||
for issue_data in data.get("issues", []): | ||||||
issue = Issue(jira_client, issue_data) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect Issue instantiation; pass options/session and raw so fields are populated correctly. Prompt for AI agents
Suggested change
|
||||||
# Ensure the issue has the necessary attributes | ||||||
if not hasattr(issue, "key") and "key" in issue_data: | ||||||
issue.key = issue_data["key"] | ||||||
issues.append(issue) | ||||||
|
||||||
return issues | ||||||
|
||||||
|
||||||
def process_jira_issue( | ||||||
jira_client: JIRA, | ||||||
issue: Issue, | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: The fallback to the old search method may not work since the old endpoint is deprecated. Consider logging this as an error and failing fast instead of attempting the deprecated call.