1
1
import { AuditDiff , Commit , ReportsDiff } from '@code-pushup/models' ;
2
2
import { pluralize , pluralizeToken } from '../formatting' ;
3
3
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' ;
14
5
import { DiffOutcome } from './types' ;
15
6
import {
16
7
colorByScoreDiff ,
@@ -65,18 +56,23 @@ function formatDiffHeaderSection(diff: ReportsDiff): string {
65
56
}
66
57
67
58
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 ) {
70
65
return '' ;
71
66
}
67
+
72
68
return paragraphs (
73
69
h2 ( '🏷️ Categories' ) ,
74
- changed . length > 0 &&
70
+ categoriesCount > 0 &&
75
71
tableMd (
76
72
[
77
73
[
78
74
'🏷️ Category' ,
79
- '⭐ Current score' ,
75
+ hasChanges ? '⭐ Current score' : '⭐ Score ',
80
76
'⭐ Previous score' ,
81
77
'🗠 Score change' ,
82
78
] ,
@@ -86,17 +82,20 @@ function formatDiffCategoriesSection(diff: ReportsDiff): string {
86
82
formatScoreWithColor ( category . scores . before , { skipBold : true } ) ,
87
83
formatScoreChange ( category . scores . diff ) ,
88
84
] ) ,
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' ] ,
100
99
) ,
101
100
) ;
102
101
}
0 commit comments