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

Function compileBitbucketConfig

packages/backend/src/repoCompileUtils.ts:402–567  ·  view source on GitHub ↗
(
    config: BitbucketConnectionConfig,
    connectionId: number)

Source from the content-addressed store, hash-verified

400}
401
402export const compileBitbucketConfig = async (
403 config: BitbucketConnectionConfig,
404 connectionId: number): Promise<CompileResult> => {
405
406 const bitbucketReposResult = await getBitbucketReposFromConfig(config);
407 const bitbucketRepos = bitbucketReposResult.repos;
408 const warnings = bitbucketReposResult.warnings;
409
410 const hostUrl = (config.url ?? 'https://bitbucket.org').replace(/\/+$/, '');
411 const repoNameRoot = new URL(hostUrl)
412 .toString()
413 .replace(/^https?:\/\//, '');
414
415 // For Bitbucket Server, verify that the instance-level `feature.public.access` flag is
416 // actually enabled. When it is disabled, per-repo `public` flags may still be stale
417 // (i.e., remain `true` from before the flag was turned off) but repos are no longer
418 // anonymously accessible. We detect this by making a single unauthenticated probe
419 // request to one of the repos the API reports as public.
420 let isServerPublicAccessEnabled = true;
421 if (config.deploymentType === 'server') {
422 const firstPublicRepo = bitbucketRepos.find(repo => (repo as BitbucketServerRepository).public === true);
423 if (firstPublicRepo) {
424 isServerPublicAccessEnabled = await isBitbucketServerPublicAccessEnabled(hostUrl, firstPublicRepo as BitbucketServerRepository);
425 if (!isServerPublicAccessEnabled) {
426 logger.warn(`Bitbucket Server at ${hostUrl} has repos marked as public but they are not anonymously accessible. The feature.public.access flag may be disabled. Treating all repos as private.`);
427 }
428 }
429 }
430
431 const getCloneUrl = (repo: BitbucketRepository) => {
432 if (!repo.links) {
433 throw new Error(`No clone links found for server repo ${repo.name}`);
434 }
435
436 // In the cloud case we simply fetch the html link and use that as the clone url. For server we
437 // need to fetch the actual clone url
438 if (config.deploymentType === 'cloud') {
439 const htmlLink = repo.links.html as { href: string };
440 return htmlLink.href;
441 }
442
443 const cloneLinks = repo.links.clone as {
444 href: string;
445 name: string;
446 }[];
447
448 for (const link of cloneLinks) {
449 if (link.name === 'http') {
450 return link.href;
451 }
452 }
453
454 throw new Error(`No clone links found for repo ${repo.name}`);
455 }
456
457 const getWebUrl = (repo: BitbucketRepository) => {
458 const isServer = config.deploymentType === 'server';
459 const repoLinks = (repo as BitbucketServerRepository | BitbucketCloudRepository).links;

Callers 1

runJobMethod · 0.85

Calls 5

getCloneUrlFunction · 0.85
getWebUrlFunction · 0.85
marshalBoolFunction · 0.85

Tested by

no test coverage detected