-
Notifications
You must be signed in to change notification settings - Fork 143
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.
packages/backend/src/bitbucket.ts
Outdated
/** | ||
* 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
.
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.
Sorry guys, there was a bug in my code due to a change I had made at the last moment and I was sure I had tested it.
I made the modifications that @brendan-kellam suggested. I think it looks cleaner, the only issue is that the path was left with /2.0
at the beginning and I had no other option but to remove it in a hacky way with a regex.
Another option is to always keep the original path fixed and only get the query params from the next url, but that's not ideal either.
@WendelBartzUbots can you try again please?
Let me know if you see anything else to adjust or if you prefer another approach.
Thanks!
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