Skip to content

fix(bitbucket): Fetch all repository pages from Bitbucket Cloud API#112514

Merged
jaydgoss merged 7 commits intomasterfrom
jaygoss/vdy-67-fix-bitbucket-repo-pagination
Apr 9, 2026
Merged

fix(bitbucket): Fetch all repository pages from Bitbucket Cloud API#112514
jaydgoss merged 7 commits intomasterfrom
jaygoss/vdy-67-fix-bitbucket-repo-pagination

Conversation

@jaydgoss
Copy link
Copy Markdown
Member

@jaydgoss jaydgoss commented Apr 8, 2026

Summary

  • Bitbucket Cloud defaults to pagelen=10 when no parameter is specified, so get_repos() was silently returning only the first 10 repositories for any workspace
  • This affected repo selector dropdowns, stacktrace linking, code mappings, and unmigratable repo detection for any Bitbucket Cloud workspace with >10 repos
  • Add _get_all_from_paginated() that follows the next URL in Bitbucket response bodies with pagelen=100 (the API max), aggregating all pages
  • Applied to get_repos() only; search_repositories() is left unchanged

Test plan

  • Existing Bitbucket tests pass (65/65)
  • Manually test with a Bitbucket Cloud workspace that has >10 repos to confirm all repos are now returned

Refs VDY-67

@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 8, 2026

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 8, 2026
@jaydgoss jaydgoss changed the title fix(bitbucket): Add pagination to Bitbucket Cloud repository fetching fix(bitbucket): Fetch all repository pages from Bitbucket Cloud API Apr 8, 2026
@jaydgoss jaydgoss marked this pull request as ready for review April 8, 2026 20:26
@jaydgoss jaydgoss requested review from a team as code owners April 8, 2026 20:26
jaydgoss added 4 commits April 8, 2026 15:48
Bitbucket Cloud defaults to pagelen=10 when no parameter is specified,
so get_repos() was silently returning only the first 10 repositories
for any workspace. This affected repo selector dropdowns, stacktrace
linking, code mappings, and unmigratable repo detection.

Add _get_all_from_paginated() that follows the "next" URL in Bitbucket
response bodies with pagelen=100 (the API max), aggregating all pages.
Apply to get_repos() only; search_repositories() is left unchanged.

Refs VDY-67
Address PR feedback: forward the page_number_limit parameter from
get_repositories() through get_repos() to _get_all_from_paginated()
for consistency with the GitHub integration's interface contract.

Add tests for multi-page aggregation and page limit enforcement.

Refs VDY-67
@jaydgoss jaydgoss force-pushed the jaygoss/vdy-67-fix-bitbucket-repo-pagination branch from a452894 to ea9d018 Compare April 8, 2026 20:49
Comment thread tests/sentry/integrations/bitbucket/test_integration.py
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Backend Test Failures

Failures on 2de2916 in this run:

tests/sentry/integrations/bitbucket/test_integration.py::BitbucketIntegrationTest::test_get_repositories_multiple_pageslog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/integrations/bitbucket/test_integration.py:92: in test_get_repositories_multiple_pages
    result = installation.get_repositories()
src/sentry/integrations/bitbucket/integration.py:148: in get_repositories
    "external_id": self.get_repo_external_id(repo),
src/sentry/integrations/bitbucket/integration.py:133: in get_repo_external_id
    return str(repo["uuid"])
E   KeyError: 'uuid'
tests/sentry/integrations/bitbucket/test_integration.py::BitbucketIntegrationTest::test_get_repositories_respects_page_limitlog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/sentry/integrations/bitbucket/test_integration.py:120: in test_get_repositories_respects_page_limit
    result = installation.get_repositories(page_number_limit=1)
src/sentry/integrations/bitbucket/integration.py:148: in get_repositories
    "external_id": self.get_repo_external_id(repo),
src/sentry/integrations/bitbucket/integration.py:133: in get_repo_external_id
    return str(repo["uuid"])
E   KeyError: 'uuid'

Mock response data was missing the uuid field that
get_repo_external_id() requires, causing KeyError. Assertions were
also missing the external_id key in expected results.

Refs VDY-67
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 53be095. Configure here.

Comment thread src/sentry/integrations/bitbucket/client.py
Type the username property return and rename a shadowed variable to
fix arg-type, no-redef, and return-value errors caught by CI.
Drop the < 1 guard so that zero/negative limits naturally return only
the first page (the while loop never executes), matching how GitHub's
_get_with_pagination handles the same case. Add tests for both the
zero-limit and excessive-limit clamping paths.
@jaydgoss jaydgoss merged commit 8c171b9 into master Apr 9, 2026
56 checks passed
@jaydgoss jaydgoss deleted the jaygoss/vdy-67-fix-bitbucket-repo-pagination branch April 9, 2026 15:40
george-sentry pushed a commit that referenced this pull request Apr 9, 2026
…112514)

## Summary

- Bitbucket Cloud defaults to `pagelen=10` when no parameter is
specified, so `get_repos()` was silently returning only the first 10
repositories for any workspace
- This affected repo selector dropdowns, stacktrace linking, code
mappings, and unmigratable repo detection for any Bitbucket Cloud
workspace with >10 repos
- Add `_get_all_from_paginated()` that follows the `next` URL in
Bitbucket response bodies with `pagelen=100` (the API max), aggregating
all pages
- Applied to `get_repos()` only; `search_repositories()` is left
unchanged

## Test plan

- [x] Existing Bitbucket tests pass (65/65)
- [x] Manually test with a Bitbucket Cloud workspace that has >10 repos
to confirm all repos are now returned

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

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants