(orgs: string[], octokit: Octokit, signal: AbortSignal, url?: string)
| 364 | } |
| 365 | |
| 366 | const getReposForOrgs = async (orgs: string[], octokit: Octokit, signal: AbortSignal, url?: string) => { |
| 367 | const results = await Promise.allSettled(orgs.map((org) => githubQueryLimit(async () => { |
| 368 | try { |
| 369 | logger.debug(`Fetching repository info for org ${org}...`); |
| 370 | |
| 371 | const octokitToUse = await getOctokitWithGithubApp(octokit, org, url, `org ${org}`); |
| 372 | const { durationMs, data } = await measure(async () => { |
| 373 | // @note: We use paginate.iterator() instead of paginate() to check |
| 374 | // signal.aborted between pages. paginate() only passes the signal to |
| 375 | // individual fetch requests but doesn't check abort state between pages. |
| 376 | const fetchFn = async () => { |
| 377 | const allRepos: OctokitRepository[] = []; |
| 378 | const iterator = octokitToUse.paginate.iterator(octokitToUse.repos.listForOrg, { |
| 379 | org: org, |
| 380 | per_page: 100, |
| 381 | request: { |
| 382 | signal |
| 383 | } |
| 384 | }); |
| 385 | |
| 386 | for await (const { data: repos } of iterator) { |
| 387 | if (signal.aborted) { |
| 388 | throw new DOMException('Operation aborted', 'AbortError'); |
| 389 | } |
| 390 | allRepos.push(...repos); |
| 391 | } |
| 392 | |
| 393 | return allRepos; |
| 394 | }; |
| 395 | |
| 396 | return fetchWithRetry(fetchFn, `org ${org}`, logger); |
| 397 | }); |
| 398 | |
| 399 | logger.debug(`Found ${data.length} in org ${org} in ${durationMs}ms.`); |
| 400 | return { |
| 401 | type: 'valid' as const, |
| 402 | data |
| 403 | }; |
| 404 | } catch (error) { |
| 405 | Sentry.captureException(error); |
| 406 | logger.error(`Failed to fetch repositories for org ${org}.`, error); |
| 407 | |
| 408 | if (isHttpError(error, 404)) { |
| 409 | const warning = `Organization ${org} not found or no access`; |
| 410 | logger.warn(warning); |
| 411 | return { |
| 412 | type: 'warning' as const, |
| 413 | warning |
| 414 | }; |
| 415 | } |
| 416 | throw error; |
| 417 | } |
| 418 | }))); |
| 419 | |
| 420 | throwIfAnyFailed(results); |
| 421 | const { validItems: repos, warnings } = processPromiseResults<OctokitRepository>(results); |
| 422 | |
| 423 | return { |
no test coverage detected