Skip to content

fix(jira): Fix querying issues on jira cloud instance #18513

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

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.atlassian.jira.rest.client.api.SearchRestClient;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.internal.async.AsynchronousCloudSearchRestClient;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.Processor;
Expand Down Expand Up @@ -125,18 +126,26 @@ protected Queue<Issue> getIssues(String jql, int start, int maxPerQuery, int max
Set<Issue> issues = new LinkedHashSet<>();
while (true) {
SearchRestClient searchRestClient = endpoint.getClient().getSearchClient();
SearchResult searchResult = searchRestClient.searchJql(jql, maxPerQuery, start, null).claim();
// *navigable should be the default value, but it does not seem to be true with 6.0.2 client
SearchResult searchResult = searchRestClient.searchJql(jql, maxPerQuery, start, Set.of("*navigable")).claim();

for (Issue issue : searchResult.getIssues()) {
issues.add(issue);
}

// Note: #getTotal == the total # the query would return *without* pagination, effectively telling us
// Note: the total # the query would return *without* pagination, effectively telling us
// we've reached the end. Also exit early if we're limiting the # of results or
// if total # of returned issues is lower than the actual page size.
if (maxPerQuery >= searchResult.getTotal() ||
start >= searchResult.getTotal() ||
maxResults > 0 && issues.size() >= maxResults) {
int total;
if (searchRestClient instanceof AsynchronousCloudSearchRestClient) {
// calling searchResult.getTotal() on AsynchronousCloudSearchRestClient throws an exception:
// Total is not available in the Cloud version of the new Search API response.
// Please use `SearchRestClient.totalCount` instead to fetch the estimated count of the issues for a given JQL
total = searchRestClient.totalCount(jql).claim().getCount();
} else {
total = searchResult.getTotal();
}
if (maxPerQuery >= total || start >= total || maxResults > 0 && issues.size() >= maxResults) {
break;
}

Expand Down
Loading