MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getReposForOrgs

Function getReposForOrgs

packages/backend/src/github.ts:366–427  ·  view source on GitHub ↗
(orgs: string[], octokit: Octokit, signal: AbortSignal, url?: string)

Source from the content-addressed store, hash-verified

364}
365
366const 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 {

Callers 1

getGitHubReposFromConfigFunction · 0.70

Calls 6

getOctokitWithGithubAppFunction · 0.85
throwIfAnyFailedFunction · 0.85
processPromiseResultsFunction · 0.85
measureFunction · 0.70
fetchWithRetryFunction · 0.70
isHttpErrorFunction · 0.70

Tested by

no test coverage detected