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

Function getReposForOrganizations

packages/backend/src/azuredevops.ts:160–229  ·  view source on GitHub ↗
(
    organizations: string[],
    baseUrl: string,
    token: string,
    useTfsPath: boolean
)

Source from the content-addressed store, hash-verified

158};
159
160async function getReposForOrganizations(
161 organizations: string[],
162 baseUrl: string,
163 token: string,
164 useTfsPath: boolean
165) {
166 const results = await Promise.allSettled(organizations.map(async (org) => {
167 try {
168 logger.debug(`Fetching repositories for organization ${org}...`);
169
170 const { durationMs, data } = await measure(async () => {
171 const fetchFn = async () => {
172 const orgUrl = buildOrgUrl(baseUrl, org, useTfsPath);
173 const connection = createAzureDevOpsConnection(orgUrl, token); // useTfsPath already handled in orgUrl
174
175 const coreApi = await connection.getCoreApi();
176 const gitApi = await connection.getGitApi();
177
178 const projects = await coreApi.getProjects();
179 const allRepos: GitRepository[] = [];
180 for (const project of projects) {
181 if (!project.id) {
182 logger.warn(`Encountered project in org ${org} with no id: ${project.name}`);
183 continue;
184 }
185
186 try {
187 const repos = await gitApi.getRepositories(project.id);
188 allRepos.push(...repos);
189 } catch (error) {
190 logger.warn(`Failed to fetch repositories for project ${project.name}: ${error}`);
191 }
192 }
193
194 return allRepos;
195 };
196
197 return fetchWithRetry(fetchFn, `organization ${org}`, logger);
198 });
199
200 logger.debug(`Found ${data.length} repositories in organization ${org} in ${durationMs}ms.`);
201 return {
202 type: 'valid' as const,
203 data
204 };
205 } catch (error) {
206 Sentry.captureException(error);
207 logger.error(`Failed to fetch repositories for organization ${org}.`, error);
208
209 // Check if it's a 404-like error (organization not found)
210 if (error && typeof error === 'object' && 'statusCode' in error && error.statusCode === 404) {
211 const warning = `Organization ${org} not found or no access`;
212 logger.warn(warning);
213 return {
214 type: 'warning' as const,
215 warning
216 };
217 }

Callers 1

Calls 4

throwIfAnyFailedFunction · 0.85
processPromiseResultsFunction · 0.85
measureFunction · 0.70
fetchWithRetryFunction · 0.70

Tested by

no test coverage detected