MCPcopy Create free account
hub / github.com/code-pushup/cli / mergeDiffs

Function mergeDiffs

packages/core/src/lib/merge-diffs.ts:14–54  ·  view source on GitHub ↗
(
  files: string[],
  persistConfig: Required<PersistConfig>,
)

Source from the content-addressed store, hash-verified

12} from '@code-pushup/utils';
13
14export async function mergeDiffs(
15 files: string[],
16 persistConfig: Required<PersistConfig>,
17): Promise<string> {
18 const results = await Promise.allSettled(
19 files.map(async file => {
20 const json = await readJsonFile(file).catch((error: unknown) => {
21 throw new Error(
22 `Failed to read JSON file ${file} - ${stringifyError(error)}`,
23 );
24 });
25 const result = await reportsDiffSchema.safeParseAsync(json);
26 if (!result.success) {
27 throw new Error(
28 `Invalid reports diff in ${file} - ${result.error.message}`,
29 );
30 }
31 return { ...result.data, file };
32 }),
33 );
34 results.filter(isPromiseRejectedResult).forEach(({ reason }) => {
35 logger.warn(`Skipped invalid report diff - ${stringifyError(reason)}`);
36 });
37 const diffs = results
38 .filter(isPromiseFulfilledResult)
39 .map(({ value }) => value);
40
41 const labeledDiffs = diffs.map(diff => ({
42 ...diff,
43 label: diff.label || path.basename(path.dirname(diff.file)), // fallback is parent folder name
44 }));
45
46 const markdown = generateMdReportsDiffForMonorepo(labeledDiffs);
47
48 const { outputDir, filename } = persistConfig;
49 const outputPath = path.join(outputDir, `${filename}-diff.md`);
50 await ensureDirectoryExists(outputDir);
51 await writeFile(outputPath, markdown);
52
53 return outputPath;
54}

Callers 2

Calls 6

readJsonFileFunction · 0.90
stringifyErrorFunction · 0.90
ensureDirectoryExistsFunction · 0.90
writeFileFunction · 0.85
warnMethod · 0.80

Tested by

no test coverage detected