Next Return the next item in the result set and advance the iterator. Advancing the iterator may require fetching a new page.
()
| 535 | // Next Return the next item in the result set and advance the iterator. |
| 536 | // Advancing the iterator may require fetching a new page. |
| 537 | func (si *SearchIterator) Next() *Issue { |
| 538 | if si.Err != nil { |
| 539 | return nil |
| 540 | } |
| 541 | |
| 542 | issue := si.searchResult.Issues[si.itemIdx] |
| 543 | if si.itemIdx+1 < len(si.searchResult.Issues) { |
| 544 | // We still have an item left in the currently cached page |
| 545 | si.itemIdx++ |
| 546 | } else { |
| 547 | if si.searchResult.IsLastPage() { |
| 548 | si.Err = errDone |
| 549 | } else { |
| 550 | // There are still more pages to fetch, so fetch the next page and |
| 551 | // cache it |
| 552 | si.searchResult, si.Err = si.client.Search( |
| 553 | si.jql, si.pageSize, si.searchResult.NextStartAt()) |
| 554 | // NOTE(josh): we don't deal with the error now, we just cache it. |
| 555 | // HasNext() will return false and the caller can check the error |
| 556 | // afterward. |
| 557 | si.itemIdx = 0 |
| 558 | } |
| 559 | } |
| 560 | return &issue |
| 561 | } |
| 562 | |
| 563 | // IterSearch return an iterator over paginated results for a JQL search |
| 564 | func (client *Client) IterSearch(jql string, pageSize int) *SearchIterator { |
no test coverage detected