Skip to content

Commit c834cfa

Browse files
committed
feat(utils): skip unchanged categories and projects in report-diff.md
1 parent 3cf7b11 commit c834cfa

File tree

3 files changed

+62
-36
lines changed

3 files changed

+62
-36
lines changed

packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo-with-portal.md

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@
4343

4444
</details>
4545

46-
## 💼 Project `backoffice` – unchanged 😐
46+
---
4747

48-
[🕵️ See full comparison in Code PushUp portal 🔍](https://app.code-pushup.dev/portal/dunder-mifflin/backoffice/comparison/abcdef0123456789abcdef0123456789abcdef01/0123456789abcdef0123456789abcdef01234567)
49-
50-
| 🏷️ Category | ⭐ Score |
51-
| :------------- | :-----: |
52-
| Performance | 🟢 92 |
53-
| Bug prevention | 🟡 68 |
54-
| Code style | 🟡 54 |
48+
1 other project is unchanged.

packages/utils/src/lib/reports/__snapshots__/report-diff-monorepo.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
4848
| Bug prevention | 🟡 68 | 🟡 **63** | ![↓ −5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) |
4949
| Performance | 🟢 92 | 🟢 **94** | ![↑ +2](https://img.shields.io/badge/%E2%86%91%20%2B2-green) |
50-
| Code style | 🟡 54 | 🟡 **54** ||
50+
51+
1 other category is unchanged.
5152

5253
<details>
5354
<summary>👍 <strong>1</strong> group improved, 👍 <strong>3</strong> audits improved, 👎 <strong>1</strong> audit regressed</summary>
@@ -73,24 +74,17 @@
7374

7475
</details>
7576

76-
## 💼 Project `marketing` – unchanged 😐
77-
78-
| 🏷️ Category | ⭐ Score |
79-
| :------------- | :-----: |
80-
| Performance | 🟢 92 |
81-
| Bug prevention | 🟡 68 |
82-
| Code style | 🟡 54 |
83-
8477
## 💼 Project `docs` – regressed 😟
8578

8679
| 🏷️ Category | ⭐ Previous score | ⭐ Current score | 🔄 Score change |
8780
| :------------- | :--------------: | :-------------: | :--------------------------------------------------------------: |
8881
| Bug prevention | 🟡 68 | 🟡 **63** | ![↓ −5](https://img.shields.io/badge/%E2%86%93%20%E2%88%925-red) |
8982
| Performance | _n/a (\*)_ | 🟢 **94** | _n/a (\*)_ |
90-
| Code style | 🟡 54 | 🟡 **54** ||
9183

9284
_(\*) New category._
9385

86+
1 other category is unchanged.
87+
9488
<details>
9589
<summary>👎 <strong>1</strong> audit regressed</summary>
9690

@@ -107,3 +101,7 @@ All of 1 group is unchanged.
107101
49 other audits are unchanged.
108102

109103
</details>
104+
105+
---
106+
107+
1 other project is unchanged.

packages/utils/src/lib/reports/generate-md-reports-diff.ts

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,38 @@ export type ProjectDiff = {
4040
diff: ReportsDiff;
4141
};
4242

43+
export type ProjectDiffWithOutcome = ProjectDiff & {
44+
outcome: DiffOutcome;
45+
};
46+
4347
export function generateMdReportsDiffForMonorepo(
4448
projects: ProjectDiff[],
4549
): string {
4650
// TODO: sort projects (most changed, alphabetical)
47-
// TODO: abbreviate or filter out unchanged projects?
51+
const projectsWithOutcomes = projects.map(
52+
(project): ProjectDiffWithOutcome => ({
53+
...project,
54+
outcome: mergeDiffOutcomes(
55+
changesToDiffOutcomes(getDiffChanges(project.diff)),
56+
),
57+
}),
58+
);
59+
const unchanged = projectsWithOutcomes.filter(
60+
({ outcome }) => outcome === 'unchanged',
61+
);
62+
const changed = projectsWithOutcomes.filter(
63+
project => !unchanged.includes(project),
64+
);
65+
4866
return new MarkdownDocument()
4967
.$concat(
5068
createDiffHeaderSection(projects.map(({ diff }) => diff)),
51-
...projects.map(createDiffProjectSection),
69+
...changed.map(createDiffProjectSection),
70+
)
71+
.$if(unchanged.length > 0, doc =>
72+
doc
73+
.rule()
74+
.paragraph(summarizeUnchanged('project', { unchanged, changed })),
5275
)
5376
.toString();
5477
}
@@ -84,34 +107,38 @@ function createDiffHeaderSection(
84107
.paragraph(formatPortalLink(portalUrl));
85108
}
86109

87-
function createDiffProjectSection(project: ProjectDiff): MarkdownDocument {
110+
function createDiffProjectSection(
111+
project: ProjectDiffWithOutcome,
112+
): MarkdownDocument {
88113
const outcomeTexts = {
89114
positive: 'improved 🥳',
90115
negative: 'regressed 😟',
91116
mixed: 'mixed 🤨',
92117
unchanged: 'unchanged 😐',
93118
};
94-
const outcome = mergeDiffOutcomes(
95-
changesToDiffOutcomes(getDiffChanges(project.diff)),
96-
);
119+
const outcomeText = outcomeTexts[project.outcome];
97120

98121
return new MarkdownDocument()
99122
.heading(
100123
HIERARCHY.level_2,
101-
md`💼 Project ${md.code(project.name)}${outcomeTexts[outcome]}`,
124+
md`💼 Project ${md.code(project.name)}${outcomeText}`,
102125
)
103126
.paragraph(formatPortalLink(project.portalUrl))
104127
.$concat(
105-
createDiffCategoriesSection(project.diff, { skipHeading: true }),
128+
createDiffCategoriesSection(project.diff, {
129+
skipHeading: true,
130+
skipUnchanged: true,
131+
}),
106132
createDiffDetailsSection(project.diff, HIERARCHY.level_3),
107133
);
108134
}
109135

110136
function createDiffCategoriesSection(
111137
diff: ReportsDiff,
112-
options: { skipHeading: boolean } = { skipHeading: false },
138+
options?: { skipHeading?: boolean; skipUnchanged?: boolean },
113139
): MarkdownDocument | null {
114140
const { changed, unchanged, added } = diff.categories;
141+
const { skipHeading, skipUnchanged } = options ?? {};
115142

116143
const categoriesCount = changed.length + unchanged.length + added.length;
117144
const hasChanges = unchanged.length < categoriesCount;
@@ -145,21 +172,28 @@ function createDiffCategoriesSection(
145172
formatScoreWithColor(category.score),
146173
md.italic('n/a (\\*)'),
147174
]),
148-
...unchanged.map(category => [
149-
formatTitle(category),
150-
formatScoreWithColor(category.score, { skipBold: true }),
151-
formatScoreWithColor(category.score),
152-
'–',
153-
]),
175+
...(skipUnchanged
176+
? []
177+
: unchanged.map(category => [
178+
formatTitle(category),
179+
formatScoreWithColor(category.score, { skipBold: true }),
180+
formatScoreWithColor(category.score),
181+
'–',
182+
])),
154183
];
155184

156185
return new MarkdownDocument()
157-
.heading(HIERARCHY.level_2, !options.skipHeading && '🏷️ Categories')
186+
.heading(HIERARCHY.level_2, !skipHeading && '🏷️ Categories')
158187
.table(
159188
hasChanges ? columns : columns.slice(0, 2),
160189
rows.map(row => (hasChanges ? row : row.slice(0, 2))),
161190
)
162-
.paragraph(added.length > 0 && md.italic('(\\*) New category.'));
191+
.paragraph(added.length > 0 && md.italic('(\\*) New category.'))
192+
.paragraph(
193+
skipUnchanged &&
194+
unchanged.length > 0 &&
195+
summarizeUnchanged('category', { changed, unchanged }),
196+
);
163197
}
164198

165199
function createDiffDetailsSection(
@@ -270,7 +304,7 @@ function createGroupsOrAuditsDetails<T extends 'group' | 'audit'>(
270304
}
271305

272306
function summarizeUnchanged(
273-
token: 'category' | 'group' | 'audit',
307+
token: string,
274308
{ changed, unchanged }: { changed: unknown[]; unchanged: unknown[] },
275309
): string {
276310
return [

0 commit comments

Comments
 (0)