Skip to content

fix(appset): request max page size from Bitbucket Cloud pull request API to reduce rate limiting - #30063

Open
roulettedares wants to merge 1 commit into
argoproj:masterfrom
roulettedares:fix/appset-bitbucket-cloud-pr-pagelen
Open

roulettedares wants to merge 1 commit into
argoproj:masterfrom
roulettedares:fix/appset-bitbucket-cloud-pr-pagelen

Conversation

@roulettedares

@roulettedares roulettedares commented Oct 8, 2026 •

Copy link
Copy Markdown

Problem

The Bitbucket Cloud pull request generator never sets a page size, so the underlying go-bitbucket client uses its default of 10 (DEFAULT_PAGE_LENGTH). Listing a repository's open pull requests therefore costs ceil(N/10) API calls on every ApplicationSet reconcile — e.g. 9 calls for a repo with 81 open PRs.

Bitbucket Cloud enforces a limit of 1,000 requests per hour on /2.0/repositories/* (rolling window). In a workspace with several active repositories plus a burst of PR activity (e.g. a Renovate run updating many PRs), the generator's polling exhausts that budget, and every subsequent reconcile fails with 429 Too Many Requests for over an hour.

The other pull request generators already request large pages: GitHub and GitLab use PerPage: 100, Bitbucket Server uses limit: 100. Bitbucket Cloud is the outlier.

Fix

Set Pagelen = 50 on the Bitbucket Cloud client in both the basic-auth and bearer-token constructors (the no-auth constructor routes through the bearer-token one). 50 is the maximum Bitbucket Cloud accepts for this endpoint — pagelen=100 is rejected with 400 Invalid pagelen (verified against the live API; see pagination docs, max page size varies by endpoint).

For the 81-open-PRs example this drops the cost from 9 calls to 2 per repo per reconcile — a 4–5x reduction in API consumption against the hourly budget. Pagination is unchanged: the client still follows Bitbucket's next links (which carry the requested page size).

Related context: #27644 adds webhook support for this generator, which reduces how often polling happens; this PR reduces what each poll costs. They are independent.

Testing

  • Updated the httptest-based unit tests to assert that requests to /repositories/{owner}/{repo}/pullrequests carry pagelen=50 for both the basic-auth and bearer-token constructors, and kept multi-page coverage (next links are still followed).
  • go test ./applicationset/services/pull_request/..., go vet, and golangci-lint run on the package all pass locally.
  • Verified pagelen=50 is accepted and pagelen=100 is rejected by the live Bitbucket Cloud API for the pull requests endpoint.

This is a low-risk fix that could be cherry-picked into supported release branches.

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

Summary by CodeRabbit

  • Improvements
    • Bitbucket Cloud pull-request lists now request up to 50 items per page, matching the service’s maximum supported page size. This can reduce the number of pages needed to load results, while pagination continues to retrieve additional results when available. The updated page size applies whether you connect using basic authentication or a bearer token. No changes were made to other connection behavior.

@roulettedares
roulettedares requested a review from a team as a code owner October 8, 2026 00:30
@bunnyshell

bunnyshell Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

❗ Preview Environment deployment failed on Bunnyshell

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🚀 /bns:deploy to redeploy the environment
  • ❌ /bns:delete to remove the environment

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f8286374-d0f1-42e4-aa4c-acf2bee08982
📥 Commits

Reviewing files that changed from the base of the PR and between 7b85124 and 0a982f7.

📒 Files selected for processing (2)
  • applicationset/services/pull_request/bitbucket_cloud.go
  • applicationset/services/pull_request/bitbucket_cloud_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The Bitbucket Cloud client constructors now set the page size to 50. Tests use that value for initial requests, paginated requests, and pagination links.

Changes

Bitbucket Cloud pagination

Layer / File(s) Summary
Set page size and validate requests
applicationset/services/pull_request/bitbucket_cloud.go, applicationset/services/pull_request/bitbucket_cloud_test.go
Both client constructors set the page size to 50. Tests use the configured value in request URLs and pagination fixtures, and report unexpected request URIs.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: reggie-k

Merge Risk: ⚪ Minimal · up to 0a982

The change raises the requested page size while retaining pagination coverage; no concrete merge-blocking risk is evident.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the Bitbucket Cloud page-size change and its purpose of reducing rate limiting. It is concise and directly related to the main change.
Description check ✅ Passed The description explains the problem, fix, impact, testing, and checklist status. It is mostly complete, although issue closure, build status, and feature-status compliance are not confirmed.
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

…API to reduce rate limiting

The Bitbucket Cloud pull request generator never set a page size, so the
go-bitbucket client used its default of 10. Listing a repo's open pull
requests therefore costs ceil(N/10) API calls on every ApplicationSet
reconcile. Bitbucket Cloud allows 1,000 requests per hour to the
repositories API on a rolling window, so a workspace with several active
repos (e.g. during a burst of Renovate PR updates) exhausts the budget
and reconciles fail with 429 Too Many Requests for over an hour.

Request pagelen=50, the maximum Bitbucket Cloud accepts for this endpoint
(pagelen=100 is rejected with 400 'Invalid pagelen'). This matches the
intent of the other providers, which already request 100 per page
(GitHub, GitLab, Bitbucket Server). For a repo with 81 open PRs this
drops the per-reconcile cost from 9 calls to 2.

Both the basic-auth and bearer-token constructors are covered; the
no-auth constructor routes through the bearer-token one.

Signed-off-by: Joshua S <20404891+roulettedares@users.noreply.github.com>
@codecov

codecov Bot commented Oct 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.35%. Comparing base (2a1daf3) to head (0a982f7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #30063      +/-   ##
==========================================
+ Coverage   72.34%   72.35%   +0.01%     
==========================================
  Files         434      434              
  Lines       56289    56291       +2     
==========================================
+ Hits        40721    40729       +8     
+ Misses      15568    15562       -6     
Flag Coverage Δ
e2e 30.81% <0.00%> (+<0.01%) ⬆️
unit-tests 68.36% <100.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
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.

1 participant