|
5 | 5 | the compatibility clients for Server, Data Center, and existing Cloud users. |
6 | 6 | """ |
7 | 7 |
|
8 | | -from typing import Any, Optional, Union |
| 8 | +from typing import Any, Dict, List, Optional, Union |
9 | 9 |
|
10 | 10 | from ..rest_client import AtlassianRestAPI |
11 | 11 | from .core_methods import JiraCloudCoreMethods |
@@ -38,6 +38,62 @@ def endpoint(self, resource: str, api_version: Optional[Union[str, int]] = None) |
38 | 38 | raise ValueError("Jira Cloud Core api_version must be 2 or 3") |
39 | 39 | return self.resource_url(resource, api_root="rest/api", api_version=version) |
40 | 40 |
|
| 41 | + def enhanced_jql( |
| 42 | + self, |
| 43 | + jql: str, |
| 44 | + fields: Union[str, List[str]] = "*all", |
| 45 | + nextPageToken: Optional[str] = None, |
| 46 | + limit: Optional[int] = None, |
| 47 | + expand: Optional[str] = None, |
| 48 | + ): |
| 49 | + """Search Jira Cloud issues through the v3 enhanced JQL endpoint. |
| 50 | +
|
| 51 | + Use ``nextPageToken`` from a previous response to retrieve the next |
| 52 | + page. Unlike the older search API, enhanced JQL is cursor-paginated. |
| 53 | + """ |
| 54 | + params: Dict[str, Union[str, int]] = {"jql": jql} |
| 55 | + if nextPageToken is not None: |
| 56 | + params["nextPageToken"] = str(nextPageToken) |
| 57 | + if limit is not None: |
| 58 | + params["maxResults"] = int(limit) |
| 59 | + if fields is not None: |
| 60 | + params["fields"] = ",".join(fields) if isinstance(fields, (list, tuple, set)) else fields |
| 61 | + if expand is not None: |
| 62 | + params["expand"] = expand |
| 63 | + return self.get(self.endpoint("search/jql", api_version=3), params=params) |
| 64 | + |
| 65 | + def enhanced_jql_get_list_of_tickets( |
| 66 | + self, |
| 67 | + jql: str, |
| 68 | + fields: Union[str, List[str]] = "*all", |
| 69 | + limit: Optional[int] = None, |
| 70 | + expand: Optional[str] = None, |
| 71 | + ) -> list: |
| 72 | + """Return all cursor-paginated enhanced JQL issues up to ``limit``. |
| 73 | +
|
| 74 | + When ``limit`` is omitted, iteration continues until Jira marks the |
| 75 | + result set as final. |
| 76 | + """ |
| 77 | + results = [] |
| 78 | + next_page_token = None |
| 79 | + while True: |
| 80 | + response = self.enhanced_jql( |
| 81 | + jql, |
| 82 | + fields=fields, |
| 83 | + nextPageToken=next_page_token, |
| 84 | + limit=limit, |
| 85 | + expand=expand, |
| 86 | + ) |
| 87 | + if not response: |
| 88 | + break |
| 89 | + results.extend(response.get("issues", [])) |
| 90 | + if limit is not None and len(results) >= limit: |
| 91 | + return results[:limit] |
| 92 | + next_page_token = response.get("nextPageToken") |
| 93 | + if response.get("isLast", False) or not next_page_token: |
| 94 | + break |
| 95 | + return results |
| 96 | + |
41 | 97 |
|
42 | 98 | class JiraSoftware(JiraSoftwareMethods, AtlassianRestAPI): |
43 | 99 | """Jira Software Cloud REST APIs. |
|
0 commit comments