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

Function fetchCommand

src/cli/commands/fetch.ts:11–62  ·  view source on GitHub ↗
(logger: Logger, options: FetchCommandOptions)

Source from the content-addressed store, hash-verified

9};
10
11export async function fetchCommand(logger: Logger, options: FetchCommandOptions): Promise<void> {
12 const { source, ...fetchOptions } = options;
13
14 logger.debug(`Fetching files from ${source}...`);
15
16 try {
17 const summary = await fetchFiles({
18 source,
19 options: fetchOptions,
20 logger,
21 });
22
23 // Capture JSON data if in JSON mode
24 if (logger.jsonMode) {
25 const createdFiles = summary.files
26 .filter((f) => f.status === "created")
27 .map((f) => f.relativePath);
28 const overwrittenFiles = summary.files
29 .filter((f) => f.status === "overwritten")
30 .map((f) => f.relativePath);
31 const skippedFiles = summary.files
32 .filter((f) => f.status === "skipped")
33 .map((f) => f.relativePath);
34
35 logger.captureData("source", source);
36 logger.captureData("path", fetchOptions.path);
37 logger.captureData("created", createdFiles);
38 logger.captureData("overwritten", overwrittenFiles);
39 logger.captureData("skipped", skippedFiles);
40 logger.captureData("totalFetched", summary.created + summary.overwritten + summary.skipped);
41 }
42
43 const output = formatFetchSummary(summary);
44
45 logger.success(output);
46
47 // Exit with appropriate code
48 if (summary.created + summary.overwritten === 0 && summary.skipped === 0) {
49 logger.warn("No files were fetched.");
50 }
51 } catch (error) {
52 if (error instanceof GitHubClientError) {
53 // Include auth hints in error message for JSON mode
54 const authHint =
55 error.statusCode === 401 || error.statusCode === 403
56 ? " Tip: Set GITHUB_TOKEN or GH_TOKEN environment variable, or use `GITHUB_TOKEN=$(gh auth token) rulesync fetch ...`"
57 : "";
58 throw new CLIError(`GitHub API Error: ${error.message}.${authHint}`, ErrorCodes.FETCH_FAILED);
59 }
60 throw error;
61 }
62}

Callers 2

mainFunction · 0.85
fetch.test.tsFile · 0.85

Calls 6

fetchFilesFunction · 0.85
formatFetchSummaryFunction · 0.85
debugMethod · 0.45
captureDataMethod · 0.45
successMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…