(logger: Logger, options: FetchCommandOptions)
| 9 | }; |
| 10 | |
| 11 | export 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 | } |
no test coverage detected
searching dependent graphs…