-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,21 +170,33 @@ const getPaginatedCloud = async <T>( | |
} | ||
return results; | ||
} | ||
|
||
|
||
/** | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more.
RE @WendelBartzUbots @bardock - best guess is that |
||
const path = fullUrl.pathname; | ||
const query = Object.fromEntries(fullUrl.searchParams); | ||
logger.debug(`Parsed url ${url} into path ${path} and query ${JSON.stringify(query)}`); | ||
return { path, query }; | ||
} | ||
|
||
|
||
async function cloudGetReposForWorkspace(client: BitbucketClient, workspaces: string[]): Promise<{validRepos: CloudRepository[], notFoundWorkspaces: string[]}> { | ||
const results = await Promise.allSettled(workspaces.map(async (workspace) => { | ||
try { | ||
logger.debug(`Fetching all repos for workspace ${workspace}...`); | ||
|
||
const path = `/repositories/${workspace}` as CloudGetRequestPath; | ||
const { durationMs, data } = await measure(async () => { | ||
const fetchFn = () => getPaginatedCloud<CloudRepository>(path, async (url) => { | ||
const response = await client.apiClient.GET(url, { | ||
const fetchFn = () => getPaginatedCloud<CloudRepository>(`/repositories/${workspace}` as CloudGetRequestPath, async (url) => { | ||
const { path, query } = parseUrl(url, client.baseUrl); | ||
const response = await client.apiClient.GET(path, { | ||
params: { | ||
path: { | ||
workspace, | ||
} | ||
}, | ||
query: query, | ||
} | ||
}); | ||
const { data, error } = response; | ||
|
@@ -238,11 +250,15 @@ async function cloudGetReposForProjects(client: BitbucketClient, projects: strin | |
|
||
logger.debug(`Fetching all repos for project ${project} for workspace ${workspace}...`); | ||
try { | ||
const path = `/repositories/${workspace}` as CloudGetRequestPath; | ||
const repos = await getPaginatedCloud<CloudRepository>(path, async (url) => { | ||
const response = await client.apiClient.GET(url, { | ||
const repos = await getPaginatedCloud<CloudRepository>(`/repositories/${workspace}` as CloudGetRequestPath, async (url) => { | ||
const { path, query } = parseUrl(url, client.baseUrl); | ||
const response = await client.apiClient.GET(path, { | ||
params: { | ||
path: { | ||
workspace, | ||
}, | ||
query: { | ||
...query, | ||
q: `project.key="${project_name}"` | ||
} | ||
} | ||
|
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 togetPaginatedCloud
to handleresponse.next
, I wonder if we can just move this logic intogetPaginatedCloud
directly?For example, the signature could be:
And
getPaginatedCloud
handles deconstructingresponse.next
intopath
and optionallyquery
.