You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2025/07/02 07:41:49 UTC

(camel) branch main updated: fix(jira): Fix querying issues on jira cloud instance (#18513)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new f9967df1813 fix(jira): Fix querying issues on jira cloud instance (#18513)
f9967df1813 is described below

commit f9967df181349f96a2a3a02a445bc6adaef47767
Author: Andrej Vaňo <av...@redhat.com>
AuthorDate: Wed Jul 2 09:41:41 2025 +0200

    fix(jira): Fix querying issues on jira cloud instance (#18513)
---
 .../component/jira/consumer/AbstractJiraConsumer.java | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java
index 5329a1a64f4..c9210811a5d 100644
--- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java
+++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java
@@ -26,6 +26,7 @@ import com.atlassian.jira.rest.client.api.RestClientException;
 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;
@@ -125,18 +126,26 @@ public abstract class AbstractJiraConsumer extends ScheduledBatchPollingConsumer
         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;
             }