-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Jira - adding pagination to search-issues-with-jql #18437
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
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
WalkthroughImplements pagination for Jira JQL search, adds helper methods, increases per-page cap, changes run to aggregate and return { issues }, updates field descriptions and handling, and bumps versions: action 0.0.4→0.1.0 and package 1.0.4→1.1.0. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Action as search-issues-with-jql
participant Paginator as paginate()
participant Jira as Jira API
Client->>Action: run({ jql, fields, maxResults, expand, ... })
Action->>Action: perPage = getMaxResultsPerPage()
Action->>Paginator: paginate({ params, maxResults, perPage })
loop page-by-page until maxResults or isLast
Paginator->>Jira: search({ jql, fields, startAt, maxResults: perPage, expand? })
Jira-->>Paginator: { issues[], isLast, nextPageToken? }
Paginator->>Paginator: accumulate issues
end
Paginator-->>Action: issues[]
Action-->>Client: { issues }
note right of Client: Return shape changed from raw response to { issues }
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (2)
86-91
:failFast
is not a supported parameter for JQL search. Replace withvalidateQuery
.Jira search uses
validateQuery
(“strict” | “warn”) instead offailFast
. PassingfailFast
risks 400s or being ignored.- failFast: { - type: "boolean", - label: "Fail Fast", - description: "Fail this request early if we can't retrieve all field data", - optional: true, - }, + validateQuery: { + type: "string", + label: "Validate Query", + description: "Validation strictness for the JQL query. Use 'warn' to allow unknown fields/functions.", + optional: true, + options: [ + { label: "Strict", value: "strict" }, + { label: "Warn", value: "warn" }, + ], + default: "strict", + },
143-158
: Align request params with JQL search API; removefailFast
, addvalidateQuery
, and ensure per‑page limit is respected.Also safe‑guard
expand
join and passstartAt
.const issues = await this.paginate({ $, cloudId: this.cloudId, params: { jql: this.jql, maxResults: this.getMaxResultsPerPage(), - fields: this.fields, - expand: this.expand - ? this.expand.join(",") - : undefined, + fields: this.fields, + expand: Array.isArray(this.expand) && this.expand.length + ? this.expand.join(",") + : undefined, properties: this.properties, fieldsByKeys: this.fieldsByKeys, - failFast: this.failFast, + validateQuery: this.validateQuery, + startAt: 0, }, maxResults: this.maxResults, });
🧹 Nitpick comments (5)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (5)
20-21
: Typo: duplicated word in description.“The JQL query query…” → “The JQL query…”
- description: "The JQL query query to search for issues. [See the documentation for syntax and examples](https://support.atlassian.com/jira-software-cloud/docs/what-is-advanced-search-in-jira-cloud/)", + description: "The JQL query to search for issues. [See the documentation for syntax and examples](https://support.atlassian.com/jira-software-cloud/docs/what-is-advanced-search-in-jira-cloud/)",
25-30
: Clarify “Max Results” semantics (total vs per‑page).You set UI max to 5000 but per‑page to 1000. Consider clarifying label/desc to “Total results to retrieve (paginated, up to 1000 per page)”.
- label: "Max Results", - description: "Maximum number of issues to return (default: 50)", + label: "Max Results (Total)", + description: "Total number of issues to return across pages (default: 50, fetched in pages of up to 1000)",
31-37
: Optional: consider a lighter default forfields
.
*all
can be heavy; consider a curated default (e.g.,*all,-comment
) or documenting tradeoffs.
39-73
: Optional: warn aboutchangelog
expand cost.
expand=changelog
on search can explode payload size. Consider a help text note.
93-140
: Add basic rate‑limit/backoff handling in pagination.Jira Cloud can 429; add minimal retry with exponential backoff to harden the action.
I can add a small wrapper with jittered retries if you want.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs
(4 hunks)components/jira/package.json
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (2)
components/jira/jira.app.mjs (2)
params
(242-253)params
(288-299)components/jira/actions/common/issue.mjs (2)
maxResults
(54-54)maxResults
(82-82)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Publish TypeScript components
- GitHub Check: Verify TypeScript components
- GitHub Check: Lint Code Base
🔇 Additional comments (4)
components/jira/package.json (1)
3-3
: Version bump looks good.Package version aligns with the action’s 0.1.0 change. No issues.
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (3)
7-7
: Action version bump is appropriate.Breaking return shape justifies 0.1.0. Good.
159-163
: Return shape change is fine; update docs and examples.Since you now return
{ issues }
and set$summary
, ensure README/action description and any example workflows are updated accordingly.
93-140
: Unit/integration coverage for pagination.Add tests for: exact page boundary, partial last page, maxResults < page size, empty results.
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs
Show resolved
Hide resolved
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.
Actionable comments posted: 1
🧹 Nitpick comments (2)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (2)
148-149
: Minor: per-page value could be decoupled from total limit.Using
this.maxResults
to derive per-page can make pages unnecessarily small for low totals. Consider a fixed per-page default (e.g., 100) independent from the total cap, still bounded by the API max.Example:
- maxResults: this.getMaxResultsPerPage(), + maxResults: Math.min(100, this.getMaxResultsPerPage()),
163-165
: Improve error context surfaced to users.Include HTTP status and response data when available.
- } catch (error) { - throw new Error(`Failed to search issues: ${error.message}`); - } + } catch (error) { + const status = error?.response?.status; + const statusText = error?.response?.statusText; + const details = error?.response?.data?.errorMessages?.join("; ") + || error?.response?.data?.message + || error.message; + throw new Error(`Failed to search issues${status ? ` (${status}${statusText ? ` ${statusText}` : ""})` : ""}: ${details}`); + }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs
(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (2)
components/jira/jira.app.mjs (3)
response
(341-354)params
(242-253)params
(288-299)components/jira/actions/common/issue.mjs (2)
maxResults
(54-54)maxResults
(82-82)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Verify TypeScript components
- GitHub Check: Publish TypeScript components
- GitHub Check: Lint Code Base
- GitHub Check: pnpm publish
🔇 Additional comments (2)
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs (2)
7-7
: Output shape change: verify downstream usage and versioning.Returning
{ issues }
(vs a raw response) can break consumers. Ensure callers and docs are updated; version bump to 0.1.0 is appropriate if this is breaking.If you need to preserve compatibility, consider returning both:
- return { - issues, - }; + return { + issues, + // total, startAt could be exposed in the future if needed + };Also applies to: 159-162
97-139
: Fix pagination: Jira JQL search uses startAt/maxResults/total, not nextPageToken/isLast.Current loop will only fetch the first page. Replace cursor-style pagination with offset pagination.
Apply this diff:
methods: { getMaxResultsPerPage() { return Math.min(this.maxResults, 1000); }, async paginate({ - params, maxResults, ...otherArgs + params, maxResults, ...otherArgs }) { - const results = []; - let nextPageToken; - let response; - - do { - response = await this.jira.searchIssues({ - ...otherArgs, - params: { - ...params, - ...(nextPageToken && { - nextPageToken, - }), - }, - }); - - const pageResults = response.issues; - const pageLength = pageResults?.length; - if (!pageLength) { - break; - } - - // If maxResults is specified, only add what we need - if (maxResults && results.length + pageLength > maxResults) { - const remainingSlots = maxResults - results.length; - results.push(...pageResults.slice(0, remainingSlots)); - break; - } else { - results.push(...pageResults); - } - - // Also break if we've reached maxResults exactly - if (maxResults && results.length >= maxResults) { - break; - } - - nextPageToken = response.nextPageToken; - } while (nextPageToken && !response.isLast); - - return results; + const results = []; + let startAt = Number(params?.startAt || 0); + const perPage = Number(params?.maxResults) || this.getMaxResultsPerPage(); + const pageSize = Math.min(perPage, 1000); + + for (;;) { + const { issues: page = [], total = 0 } = await this.jira.searchIssues({ + ...otherArgs, + params: { + ...params, + startAt, + maxResults: pageSize, + }, + }); + + const pageLen = page.length; + if (pageLen === 0) break; + + if (maxResults && results.length + pageLen > maxResults) { + results.push(...page.slice(0, maxResults - results.length)); + break; + } + results.push(...page); + + if ((maxResults && results.length >= maxResults) || + startAt + pageLen >= total) { + break; + } + startAt += pageLen; + } + return results; }, },
components/jira/actions/search-issues-with-jql/search-issues-with-jql.mjs
Show resolved
Hide resolved
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.
LGTM!
(reported by a customer)
Component did not have pagination, only max results, limiting the amount of responses that could be retrieved.
I've increased the max page size (1000, or less if
maxResults
is less) and added pagination, raising the maxmaxResults
to 5000. While technically we can allow larger values, I think at this point the user should improve their query to narrow down the results, as the execution time can skyrocket.Summary by CodeRabbit
New Features
Documentation
Chores