MCPcopy Create free account
hub / github.com/dyoshikawa/rulesync / fetchAndConvertToolFiles

Function fetchAndConvertToolFiles

src/lib/fetch.ts:519–635  ·  view source on GitHub ↗

* Fetch tool-specific files and convert them to rulesync format

(params: {
  client: GitHubClient;
  parsed: ParsedSource;
  ref: string;
  resolvedPath: string;
  enabledFeatures: Feature[];
  target: ToolTarget;
  outputDir: string;
  outputRoot: string;
  conflictStrategy: ConflictStrategy;
  logger: Logger;
})

Source from the content-addressed store, hash-verified

517 * Fetch tool-specific files and convert them to rulesync format
518 */
519async function fetchAndConvertToolFiles(params: {
520 client: GitHubClient;
521 parsed: ParsedSource;
522 ref: string;
523 resolvedPath: string;
524 enabledFeatures: Feature[];
525 target: ToolTarget;
526 outputDir: string;
527 outputRoot: string;
528 conflictStrategy: ConflictStrategy;
529 logger: Logger;
530}): Promise<FetchSummary> {
531 const {
532 client,
533 parsed,
534 ref,
535 resolvedPath,
536 enabledFeatures,
537 target,
538 outputDir,
539 outputRoot,
540 conflictStrategy: _conflictStrategy,
541 logger,
542 } = params;
543
544 // Create a unique temporary directory
545 const tempDir = await createTempDirectory();
546 logger.debug(`Created temp directory: ${tempDir}`);
547
548 // Create semaphore for concurrency control
549 const semaphore = new Semaphore(FETCH_CONCURRENCY_LIMIT);
550
551 try {
552 // Collect files using rulesync feature paths (rules/, commands/, etc.)
553 // External repos use these paths directly without tool-specific prefixes
554 const filesToFetch = await collectFeatureFiles({
555 client,
556 owner: parsed.owner,
557 repo: parsed.repo,
558 basePath: resolvedPath,
559 ref,
560 enabledFeatures,
561 semaphore,
562 logger,
563 });
564
565 if (filesToFetch.length === 0) {
566 logger.warn(`No files found matching enabled features: ${enabledFeatures.join(", ")}`);
567 return {
568 source: `${parsed.owner}/${parsed.repo}`,
569 ref,
570 files: [],
571 created: 0,
572 overwritten: 0,
573 skipped: 0,
574 };
575 }
576

Callers 1

fetchFilesFunction · 0.85

Calls 13

createTempDirectoryFunction · 0.85
collectFeatureFilesFunction · 0.85
validateFileSizeFunction · 0.85
getToolPathMappingFunction · 0.85
mapToToolPathFunction · 0.85
checkPathTraversalFunction · 0.85
withSemaphoreFunction · 0.85
writeFileContentFunction · 0.85
removeTempDirectoryFunction · 0.85
debugMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…