MCPcopy Create free account
hub / github.com/basecamp/hey-cli / paginateBoxPostings

Function paginateBoxPostings

internal/cmd/box.go:237–266  ·  view source on GitHub ↗

paginateBoxPostings follows next_history_url links to collect additional postings beyond the first page. When neither all nor a limit exceeding the first page is requested, it returns the first page only (preserving default behavior).

(ctx context.Context, firstPage *generated.BoxShowResponse, limit int, all bool, fetch pageFetcher)

Source from the content-addressed store, hash-verified

235// beyond the first page. When neither all nor a limit exceeding the first page is
236// requested, it returns the first page only (preserving default behavior).
237func paginateBoxPostings(ctx context.Context, firstPage *generated.BoxShowResponse, limit int, all bool, fetch pageFetcher) ([]generated.Posting, string, error) {
238 postings := firstPage.Postings
239 nextURL := firstPage.NextHistoryUrl
240
241 needMore := all || (limit > 0 && len(postings) < limit)
242 if !needMore || nextURL == "" {
243 return postings, nextURL, nil
244 }
245 if fetch == nil {
246 return nil, "", fmt.Errorf("paginateBoxPostings: fetch function is nil while pagination is required")
247 }
248
249 for page := 1; page <= maxAdditionalPages && nextURL != ""; page++ {
250 resp, err := fetch(ctx, nextURL)
251 if err != nil {
252 return nil, "", err
253 }
254 nextURL = resp.NextHistoryUrl
255 if len(resp.Postings) == 0 {
256 break
257 }
258 postings = append(postings, resp.Postings...)
259
260 if !all && limit > 0 && len(postings) >= limit {
261 break
262 }
263 }
264
265 return postings, nextURL, nil
266}
267
268// boxTruncationNotice returns a user-facing notice about truncated or paginated results.
269func boxTruncationNotice(shown, fetched int, hasMore, all bool) string {

Calls

no outgoing calls