Skip to content

Add --limit flag and default sort to pipeline list#59

Merged
gildas merged 3 commits intogildas:devfrom
keybrdist:feat/add-limit-flag
Mar 15, 2026
Merged

Add --limit flag and default sort to pipeline list#59
gildas merged 3 commits intogildas:devfrom
keybrdist:feat/add-limit-flag

Conversation

@keybrdist
Copy link
Contributor

Summary

  • Add --limit flag to pipeline list to cap total results, breaking the pagination loop early in GetAll
  • Default to sort=-created_on so newest pipelines are returned first
  • Cap pagelen to min(pageLength, limit) to avoid over-fetching from the API
  • The --limit support in GetAll is generic — other list commands can opt in by registering the same flag

Motivation

bb pipeline list hangs on repositories with many pipelines because GetAll fetches every page before returning any output. Unlike pullrequest list (which defaults to state=OPEN), pipeline list has no default filter and fetches all historical pipelines.

Usage

bb pipeline list --limit 20        # 20 most recent pipelines
bb pipeline list                   # all pipelines (newest first now)

Test plan

  • bb pipeline list --limit 10 returns exactly 10 pipelines
  • bb pipeline list --limit 10 completes quickly (1-2 API calls)
  • bb pipeline list without --limit still works, now sorted newest first
  • bb pipeline list --limit 5 --query 'state.name="SUCCESSFUL"' respects both flags

Fixes #57

Resubmitted against dev with signed commits per maintainer request (replaces #58).

Copilot AI review requested due to automatic review settings March 8, 2026 10:55
keybrdist and others added 2 commits March 8, 2026 04:59
Pipeline list hangs on repositories with many pipelines because GetAll
fetches every page before returning. This adds a --limit flag to cap
total results and breaks the pagination loop early. Also defaults to
sort=-created_on so newest pipelines are returned first.

Fixes gildas#57

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Update --sort flag description to clarify it applies a local sort on
  fetched results, not server-side sorting
- Cap pagelen to min(pageLength, limit) so --limit 5 only fetches 5
  items from the API instead of a full page of 50

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@keybrdist keybrdist force-pushed the feat/add-limit-flag branch from 888fcc1 to 82e5844 Compare March 8, 2026 10:59
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Bitbucket CLI’s pipeline listing behavior to avoid unbounded pagination work by introducing an optional total-result cap and by requesting pipelines from the API in newest-first order.

Changes:

  • Add generic --limit support in profile.GetAll to stop pagination once enough results are collected and to reduce pagelen when possible.
  • Add --limit flag to bb pipeline list.
  • Default the pipeline list API request to sort=-created_on (newest-first at the API level).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/profile/profile_client.go Adds generic --limit handling to GetAll, including early pagination exit and pagelen adjustment.
cmd/pipeline/list.go Adds --limit flag and requests pipelines with server-side sort=-created_on.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Log effectivePageLength and limit instead of raw pageLength
- Adjust pagelen on subsequent pages to only fetch remaining items
  when limit is set, avoiding over-fetching on the last request
- Only apply local sort when --sort is explicitly provided, preserving
  the server-side created_on descending order by default
@keybrdist
Copy link
Contributor Author

@gildas lmk if you need anything changed

@gildas
Copy link
Owner

gildas commented Mar 15, 2026

Sorry for the delay, I could not look at it lately, work was very intense. Still is, but at least I don't have to work today.

@gildas gildas merged commit 59c5084 into gildas:dev Mar 15, 2026
@gildas
Copy link
Owner

gildas commented Mar 15, 2026

thanks again for your contribution! Very much appreciated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants