Skip to content

Commit 4e53077

Browse files
committed
feat(utils): include unchanged and added categories in markdown table
1 parent 74cb57e commit 4e53077

File tree

3 files changed

+30
-42
lines changed

3 files changed

+30
-42
lines changed

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
|:--|:--:|:--:|:--:|
99
|Bug prevention|🟡 **63**|🟡 68|<span style="color: red">▼ **-5**</span>|
1010
|Performance|🟢 **94**|🟢 92|<span style="color: green">▲ **+2**</span>|
11-
12-
<details>
13-
<summary>1 other category is unchanged.</summary>
14-
15-
- Code style: 🟡 **54**
16-
17-
</details>
18-
11+
|Code style|🟡 **54**|🟡 54||
1912

2013
## 🎗️ Groups
2114

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44

55
## 🏷️ Categories
66

7-
<details>
8-
<summary>All of 3 categories are unchanged.</summary>
9-
10-
- Performance: 🟢 **92**
11-
- Bug prevention: 🟡 **68**
12-
- Code style: 🟡 **54**
13-
14-
</details>
15-
7+
|🏷️ Category|⭐ Score|
8+
|:--|:--:|
9+
|Performance|🟢 **92**|
10+
|Bug prevention|🟡 **68**|
11+
|Code style|🟡 **54**|
1612

1713
## 🎗️ Groups
1814

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

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
import { AuditDiff, Commit, ReportsDiff } from '@code-pushup/models';
22
import { pluralize, pluralizeToken } from '../formatting';
33
import { objectToEntries } from '../transform';
4-
import {
5-
Alignment,
6-
details,
7-
h1,
8-
h2,
9-
li,
10-
paragraphs,
11-
style,
12-
tableMd,
13-
} from './md';
4+
import { Alignment, details, h1, h2, paragraphs, style, tableMd } from './md';
145
import { DiffOutcome } from './types';
156
import {
167
colorByScoreDiff,
@@ -65,18 +56,23 @@ function formatDiffHeaderSection(diff: ReportsDiff): string {
6556
}
6657

6758
function formatDiffCategoriesSection(diff: ReportsDiff): string {
68-
const { changed, unchanged } = diff.categories;
69-
if (changed.length + unchanged.length === 0) {
59+
const { changed, unchanged, added } = diff.categories;
60+
61+
const categoriesCount = changed.length + unchanged.length + added.length;
62+
const hasChanges = unchanged.length < categoriesCount;
63+
64+
if (categoriesCount === 0) {
7065
return '';
7166
}
67+
7268
return paragraphs(
7369
h2('🏷️ Categories'),
74-
changed.length > 0 &&
70+
categoriesCount > 0 &&
7571
tableMd(
7672
[
7773
[
7874
'🏷️ Category',
79-
'⭐ Current score',
75+
hasChanges ? '⭐ Current score' : '⭐ Score',
8076
'⭐ Previous score',
8177
'🗠 Score change',
8278
],
@@ -86,17 +82,20 @@ function formatDiffCategoriesSection(diff: ReportsDiff): string {
8682
formatScoreWithColor(category.scores.before, { skipBold: true }),
8783
formatScoreChange(category.scores.diff),
8884
]),
89-
],
90-
['l', 'c', 'c', 'c'],
91-
),
92-
unchanged.length > 0 &&
93-
details(
94-
summarizeUnchanged('category', { changed, unchanged }),
95-
unchanged
96-
.map(category =>
97-
li(`${category.title}: ${formatScoreWithColor(category.score)}`),
98-
)
99-
.join('\n'),
85+
...added.map(category => [
86+
category.title,
87+
formatScoreWithColor(category.score),
88+
'n/a',
89+
'n/a',
90+
]),
91+
...unchanged.map(category => [
92+
category.title,
93+
formatScoreWithColor(category.score),
94+
formatScoreWithColor(category.score, { skipBold: true }),
95+
'–',
96+
]),
97+
].map(row => (hasChanges ? row : row.slice(0, 2))),
98+
hasChanges ? ['l', 'c', 'c', 'c'] : ['l', 'c'],
10099
),
101100
);
102101
}

0 commit comments

Comments
 (0)