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

Function compileGerritConfig

packages/backend/src/repoCompileUtils.ts:318–400  ·  view source on GitHub ↗
(
    config: GerritConnectionConfig,
    connectionId: number)

Source from the content-addressed store, hash-verified

316}
317
318export const compileGerritConfig = async (
319 config: GerritConnectionConfig,
320 connectionId: number): Promise<CompileResult> => {
321
322 const gerritRepos = await getGerritReposFromConfig(config);
323 const hostUrl = config.url.replace(/\/+$/, '');
324 const repoNameRoot = new URL(hostUrl)
325 .toString()
326 .replace(/^https?:\/\//, '');
327
328 const repos = gerritRepos.map((project) => {
329 const cloneUrl = new URL(path.join(hostUrl, encodeURIComponent(project.name)));
330 const repoDisplayName = project.name;
331 const repoName = path.join(repoNameRoot, repoDisplayName);
332
333 const webUrl = (() => {
334 if (!project.web_links || project.web_links.length === 0) {
335 return null;
336 }
337
338 const webLink = project.web_links[0];
339 const webUrl = webLink.url;
340
341 logger.debug(`Found gerrit repo ${project.name} with webUrl: ${webUrl}`);
342
343 // Handle case where webUrl is just a gitiles path
344 // https://github.com/GerritCodeReview/plugins_gitiles/blob/5ee7f57/src/main/java/com/googlesource/gerrit/plugins/gitiles/GitilesWeblinks.java#L50
345 if (webUrl.startsWith('/plugins/gitiles/')) {
346 logger.debug(`WebUrl is a gitiles path, joining with hostUrl: ${webUrl}`);
347 return new URL(path.join(hostUrl, webUrl)).toString();
348 } else {
349 logger.debug(`WebUrl is not a gitiles path, returning as is: ${webUrl}`);
350 return webUrl;
351 }
352 })();
353
354 const record: RepoData = {
355 external_id: project.id.toString(),
356 external_codeHostType: 'gerrit',
357 external_codeHostUrl: hostUrl,
358 cloneUrl: cloneUrl.toString(),
359 webUrl: webUrl,
360 name: repoName,
361 displayName: repoDisplayName,
362 // @note: the gerrit api doesn't return the default branch (without a seperate query).
363 // Instead, the default branch will be set once the repo is cloned.
364 // @see: repoIndexManager.ts
365 defaultBranch: undefined,
366 isFork: false,
367 isArchived: false,
368 org: {
369 connect: {
370 id: SINGLE_TENANT_ORG_ID,
371 },
372 },
373 connections: {
374 create: {
375 connectionId: connectionId,

Callers 1

runJobMethod · 0.85

Calls 2

getGerritReposFromConfigFunction · 0.85
marshalBoolFunction · 0.85

Tested by

no test coverage detected