(client: BitbucketClient, workspaces: string[])
| 211 | |
| 212 | |
| 213 | async function cloudGetReposForWorkspace(client: BitbucketClient, workspaces: string[]): Promise<{repos: CloudRepository[], warnings: string[]}> { |
| 214 | const results = await Promise.allSettled(workspaces.map(async (workspace) => { |
| 215 | try { |
| 216 | logger.debug(`Fetching all repos for workspace ${workspace}...`); |
| 217 | |
| 218 | const { durationMs, data } = await measure(async () => { |
| 219 | const fetchFn = () => getPaginatedCloud<CloudRepository>(`/repositories/${workspace}` as CloudGetRequestPath, async (path, query) => { |
| 220 | const { data } = await client.apiClient.GET(path, { |
| 221 | params: { |
| 222 | path: { |
| 223 | workspace, |
| 224 | }, |
| 225 | query: query, |
| 226 | } |
| 227 | }); |
| 228 | return data; |
| 229 | }); |
| 230 | return fetchWithRetry(fetchFn, `workspace ${workspace}`, logger); |
| 231 | }); |
| 232 | logger.debug(`Found ${data.length} repos for workspace ${workspace} in ${durationMs}ms.`); |
| 233 | |
| 234 | return { |
| 235 | type: 'valid' as const, |
| 236 | data: data, |
| 237 | }; |
| 238 | } catch (e: any) { |
| 239 | Sentry.captureException(e); |
| 240 | logger.error(`Failed to get repos for workspace ${workspace}: ${e}`); |
| 241 | |
| 242 | if (e?.status === 404) { |
| 243 | const warning = `Workspace ${workspace} not found or invalid access`; |
| 244 | logger.warn(warning); |
| 245 | return { |
| 246 | type: 'warning' as const, |
| 247 | warning |
| 248 | } |
| 249 | } |
| 250 | throw e; |
| 251 | } |
| 252 | })); |
| 253 | |
| 254 | throwIfAnyFailed(results); |
| 255 | const { validItems: repos, warnings } = processPromiseResults(results); |
| 256 | return { |
| 257 | repos, |
| 258 | warnings, |
| 259 | }; |
| 260 | } |
| 261 | |
| 262 | async function cloudGetReposForProjects(client: BitbucketClient, projects: string[]): Promise<{repos: CloudRepository[], warnings: string[]}> { |
| 263 | const results = await Promise.allSettled(projects.map(async (project) => { |
nothing calls this directly
no test coverage detected