From c834cfa1b03dbe76144f19e403eab5e820e66f91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Chalk?= Date: Wed, 14 Aug 2024 12:45:58 +0200 Subject: [PATCH] feat(utils): skip unchanged categories and projects in report-diff.md --- .../report-diff-monorepo-with-portal.md | 10 +-- .../__snapshots__/report-diff-monorepo.md | 18 +++-- .../lib/reports/generate-md-reports-diff.ts | 70 ++++++++++++++----- 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md index 4a15b5b7b..732a6cd8b 100644 --- a/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md +++ b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md @@ -43,12 +43,6 @@ -## ๐Ÿ’ผ Project `backoffice` โ€“ unchanged ๐Ÿ˜ +--- -[๐Ÿ•ต๏ธ See full comparison in Code PushUp portal ๐Ÿ”](https://app.code-pushup.dev/portal/dunder-mifflin/backoffice/comparison/abcdef0123456789abcdef0123456789abcdef01/0123456789abcdef0123456789abcdef01234567) - -| ๐Ÿท๏ธ Category | โญ Score | -| :------------- | :-----: | -| Performance | ๐ŸŸข 92 | -| Bug prevention | ๐ŸŸก 68 | -| Code style | ๐ŸŸก 54 | +1 other project is unchanged. diff --git a/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo.md b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo.md index 0c984458f..a7727808f 100644 --- a/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo.md +++ b/packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo.md @@ -47,7 +47,8 @@ | :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: | | Bug prevention | ๐ŸŸก 68 | ๐ŸŸก **63** | ![โ†“ โˆ’5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) | | Performance | ๐ŸŸข 92 | ๐ŸŸข **94** | ![โ†‘ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green) | -| Code style | ๐ŸŸก 54 | ๐ŸŸก **54** | โ€“ | + +1 other category is unchanged.
๐Ÿ‘ 1 group improved, ๐Ÿ‘ 3 audits improved, ๐Ÿ‘Ž 1 audit regressed @@ -73,24 +74,17 @@
-## ๐Ÿ’ผ Project `marketing` โ€“ unchanged ๐Ÿ˜ - -| ๐Ÿท๏ธ Category | โญ Score | -| :------------- | :-----: | -| Performance | ๐ŸŸข 92 | -| Bug prevention | ๐ŸŸก 68 | -| Code style | ๐ŸŸก 54 | - ## ๐Ÿ’ผ Project `docs` โ€“ regressed ๐Ÿ˜Ÿ | ๐Ÿท๏ธ Category | โญ Previous score | โญ Current score | ๐Ÿ”„ Score change | | :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: | | Bug prevention | ๐ŸŸก 68 | ๐ŸŸก **63** | ![โ†“ โˆ’5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) | | Performance | _n/a (\*)_ | ๐ŸŸข **94** | _n/a (\*)_ | -| Code style | ๐ŸŸก 54 | ๐ŸŸก **54** | โ€“ | _(\*) New category._ +1 other category is unchanged. +
๐Ÿ‘Ž 1 audit regressed @@ -107,3 +101,7 @@ All of 1 group is unchanged. 49 other audits are unchanged.
+ +--- + +1 other project is unchanged. diff --git a/packages/utils/src/lib/reports/generate-md-reports-diff.ts b/packages/utils/src/lib/reports/generate-md-reports-diff.ts index 68eb6d003..2d573ad8b 100644 --- a/packages/utils/src/lib/reports/generate-md-reports-diff.ts +++ b/packages/utils/src/lib/reports/generate-md-reports-diff.ts @@ -40,15 +40,38 @@ export type ProjectDiff = { diff: ReportsDiff; }; +export type ProjectDiffWithOutcome = ProjectDiff & { + outcome: DiffOutcome; +}; + export function generateMdReportsDiffForMonorepo( projects: ProjectDiff[], ): string { // TODO: sort projects (most changed, alphabetical) - // TODO: abbreviate or filter out unchanged projects? + const projectsWithOutcomes = projects.map( + (project): ProjectDiffWithOutcome => ({ + ...project, + outcome: mergeDiffOutcomes( + changesToDiffOutcomes(getDiffChanges(project.diff)), + ), + }), + ); + const unchanged = projectsWithOutcomes.filter( + ({ outcome }) => outcome === 'unchanged', + ); + const changed = projectsWithOutcomes.filter( + project => !unchanged.includes(project), + ); + return new MarkdownDocument() .$concat( createDiffHeaderSection(projects.map(({ diff }) => diff)), - ...projects.map(createDiffProjectSection), + ...changed.map(createDiffProjectSection), + ) + .$if(unchanged.length > 0, doc => + doc + .rule() + .paragraph(summarizeUnchanged('project', { unchanged, changed })), ) .toString(); } @@ -84,34 +107,38 @@ function createDiffHeaderSection( .paragraph(formatPortalLink(portalUrl)); } -function createDiffProjectSection(project: ProjectDiff): MarkdownDocument { +function createDiffProjectSection( + project: ProjectDiffWithOutcome, +): MarkdownDocument { const outcomeTexts = { positive: 'improved ๐Ÿฅณ', negative: 'regressed ๐Ÿ˜Ÿ', mixed: 'mixed ๐Ÿคจ', unchanged: 'unchanged ๐Ÿ˜', }; - const outcome = mergeDiffOutcomes( - changesToDiffOutcomes(getDiffChanges(project.diff)), - ); + const outcomeText = outcomeTexts[project.outcome]; return new MarkdownDocument() .heading( HIERARCHY.level_2, - md`๐Ÿ’ผ Project ${md.code(project.name)} โ€“ ${outcomeTexts[outcome]}`, + md`๐Ÿ’ผ Project ${md.code(project.name)} โ€“ ${outcomeText}`, ) .paragraph(formatPortalLink(project.portalUrl)) .$concat( - createDiffCategoriesSection(project.diff, { skipHeading: true }), + createDiffCategoriesSection(project.diff, { + skipHeading: true, + skipUnchanged: true, + }), createDiffDetailsSection(project.diff, HIERARCHY.level_3), ); } function createDiffCategoriesSection( diff: ReportsDiff, - options: { skipHeading: boolean } = { skipHeading: false }, + options?: { skipHeading?: boolean; skipUnchanged?: boolean }, ): MarkdownDocument | null { const { changed, unchanged, added } = diff.categories; + const { skipHeading, skipUnchanged } = options ?? {}; const categoriesCount = changed.length + unchanged.length + added.length; const hasChanges = unchanged.length < categoriesCount; @@ -145,21 +172,28 @@ function createDiffCategoriesSection( formatScoreWithColor(category.score), md.italic('n/a (\\*)'), ]), - ...unchanged.map(category => [ - formatTitle(category), - formatScoreWithColor(category.score, { skipBold: true }), - formatScoreWithColor(category.score), - 'โ€“', - ]), + ...(skipUnchanged + ? [] + : unchanged.map(category => [ + formatTitle(category), + formatScoreWithColor(category.score, { skipBold: true }), + formatScoreWithColor(category.score), + 'โ€“', + ])), ]; return new MarkdownDocument() - .heading(HIERARCHY.level_2, !options.skipHeading && '๐Ÿท๏ธ Categories') + .heading(HIERARCHY.level_2, !skipHeading && '๐Ÿท๏ธ Categories') .table( hasChanges ? columns : columns.slice(0, 2), rows.map(row => (hasChanges ? row : row.slice(0, 2))), ) - .paragraph(added.length > 0 && md.italic('(\\*) New category.')); + .paragraph(added.length > 0 && md.italic('(\\*) New category.')) + .paragraph( + skipUnchanged && + unchanged.length > 0 && + summarizeUnchanged('category', { changed, unchanged }), + ); } function createDiffDetailsSection( @@ -270,7 +304,7 @@ function createGroupsOrAuditsDetails( } function summarizeUnchanged( - token: 'category' | 'group' | 'audit', + token: string, { changed, unchanged }: { changed: unknown[]; unchanged: unknown[] }, ): string { return [