-
Notifications
You must be signed in to change notification settings - Fork 142
fix(bitbucket): Bitbucket Cloud pagination not working beyond first page #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(bitbucket): Bitbucket Cloud pagination not working beyond first page #502
Conversation
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
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. Comment |
@bardock I tested and found the following error: [dev:backend ] 2025-09-10T18:08:08.875Z error: [bitbucket] Failed to get repos for workspace facebot: TypeError: Invalid URL Apparently, the baseUrl is not being used, and when adjusting it, the issue of duplicating /2.0 occurs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!! Overall LGTM - let's make sure it's working for @WendelBartzUbots, and afterwards will be g2g to merge.
/** | ||
* Parse the url into a path and query parameters to be used with the api client (openapi-fetch) | ||
*/ | ||
function parseUrl(url: string, baseUrl: string): { path: string; query: Record<string, string>; } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are using this in all get
callbacks passed to getPaginatedCloud
to handle response.next
, I wonder if we can just move this logic into getPaginatedCloud
directly?
For example, the signature could be:
const getPaginatedCloud = async <T>(
path: CloudGetRequestPath,
get: (path: CloudGetRequestPath, query?: string) => Promise<CloudPaginatedResponse<T>>
): Promise<T[]>
And getPaginatedCloud
handles deconstructing response.next
into path
and optionally query
.
* Parse the url into a path and query parameters to be used with the api client (openapi-fetch) | ||
*/ | ||
function parseUrl(url: string, baseUrl: string): { path: string; query: Record<string, string>; } { | ||
const fullUrl = new URL(url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bardock I tested and found the following error:
[dev:backend ] 2025-09-10T18:08:08.875Z error: [bitbucket] Failed to get repos for workspace facebot: TypeError: Invalid URL [dev:backend ] 2025-09-10T18:08:08.876Z error: [connection-manager] Failed to compile repo data for connection 1 (starter-connection): TypeError: Invalid URL
Apparently, the baseUrl is not being used, and when adjusting it, the issue of duplicating /2.0 occurs.
RE @WendelBartzUbots @bardock - best guess is that url
is /repositories/${workspace}
(and not the full url) for the first call of the callback provided to getPaginatedCloud
. I think the approach I outlined above should fix this (i.e., just deconstruct response.next
and not path
)
Fix: Bitbucket Cloud pagination not working beyond first page
Problem
Issue: #295
When fetching repositories from Bitbucket Cloud workspaces with multiple pages of results, Sourcebot fails on the second page with the following error:
This is caused by the Bitbucket Cloud API returning full URLs (e.g.,
https://api.bitbucket.org/2.0/repositories/workspace?page=2
) in paginationnext
responses, butopenapi-fetch
expects separate path and query parameters. The current implementation was passing the full URL directly to the API client, which doesn't recognize the complete URL format.Solution
This PR implements proper URL parsing for Bitbucket Cloud pagination to separate paths and query parameters. The implementation includes:
1. URL Parsing Function
parseUrl()
function that properly extracts pathname and query parameters from full URLsURL
constructor for robust and performant parsing2. Updated Pagination Handlers
cloudGetReposForWorkspace()
to use parsed URL componentscloudGetReposForProjects()
to use parsed URL componentspath
andquery
parameters separately toopenapi-fetch
Testing
Breaking Changes
None. The changes are backward compatible and only affect the internal pagination URL handling.
Notes