@@ -40,15 +40,38 @@ export type ProjectDiff = {
40
40
diff : ReportsDiff ;
41
41
} ;
42
42
43
+ export type ProjectDiffWithOutcome = ProjectDiff & {
44
+ outcome : DiffOutcome ;
45
+ } ;
46
+
43
47
export function generateMdReportsDiffForMonorepo (
44
48
projects : ProjectDiff [ ] ,
45
49
) : string {
46
50
// 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
+
48
66
return new MarkdownDocument ( )
49
67
. $concat (
50
68
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 } ) ) ,
52
75
)
53
76
. toString ( ) ;
54
77
}
@@ -84,34 +107,38 @@ function createDiffHeaderSection(
84
107
. paragraph ( formatPortalLink ( portalUrl ) ) ;
85
108
}
86
109
87
- function createDiffProjectSection ( project : ProjectDiff ) : MarkdownDocument {
110
+ function createDiffProjectSection (
111
+ project : ProjectDiffWithOutcome ,
112
+ ) : MarkdownDocument {
88
113
const outcomeTexts = {
89
114
positive : 'improved 🥳' ,
90
115
negative : 'regressed 😟' ,
91
116
mixed : 'mixed 🤨' ,
92
117
unchanged : 'unchanged 😐' ,
93
118
} ;
94
- const outcome = mergeDiffOutcomes (
95
- changesToDiffOutcomes ( getDiffChanges ( project . diff ) ) ,
96
- ) ;
119
+ const outcomeText = outcomeTexts [ project . outcome ] ;
97
120
98
121
return new MarkdownDocument ( )
99
122
. heading (
100
123
HIERARCHY . level_2 ,
101
- md `💼 Project ${ md . code ( project . name ) } – ${ outcomeTexts [ outcome ] } ` ,
124
+ md `💼 Project ${ md . code ( project . name ) } – ${ outcomeText } ` ,
102
125
)
103
126
. paragraph ( formatPortalLink ( project . portalUrl ) )
104
127
. $concat (
105
- createDiffCategoriesSection ( project . diff , { skipHeading : true } ) ,
128
+ createDiffCategoriesSection ( project . diff , {
129
+ skipHeading : true ,
130
+ skipUnchanged : true ,
131
+ } ) ,
106
132
createDiffDetailsSection ( project . diff , HIERARCHY . level_3 ) ,
107
133
) ;
108
134
}
109
135
110
136
function createDiffCategoriesSection (
111
137
diff : ReportsDiff ,
112
- options : { skipHeading : boolean } = { skipHeading : false } ,
138
+ options ? : { skipHeading ? : boolean ; skipUnchanged ?: boolean } ,
113
139
) : MarkdownDocument | null {
114
140
const { changed, unchanged, added } = diff . categories ;
141
+ const { skipHeading, skipUnchanged } = options ?? { } ;
115
142
116
143
const categoriesCount = changed . length + unchanged . length + added . length ;
117
144
const hasChanges = unchanged . length < categoriesCount ;
@@ -145,21 +172,28 @@ function createDiffCategoriesSection(
145
172
formatScoreWithColor ( category . score ) ,
146
173
md . italic ( 'n/a (\\*)' ) ,
147
174
] ) ,
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
+ ] ) ) ,
154
183
] ;
155
184
156
185
return new MarkdownDocument ( )
157
- . heading ( HIERARCHY . level_2 , ! options . skipHeading && '🏷️ Categories' )
186
+ . heading ( HIERARCHY . level_2 , ! skipHeading && '🏷️ Categories' )
158
187
. table (
159
188
hasChanges ? columns : columns . slice ( 0 , 2 ) ,
160
189
rows . map ( row => ( hasChanges ? row : row . slice ( 0 , 2 ) ) ) ,
161
190
)
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
+ ) ;
163
197
}
164
198
165
199
function createDiffDetailsSection (
@@ -270,7 +304,7 @@ function createGroupsOrAuditsDetails<T extends 'group' | 'audit'>(
270
304
}
271
305
272
306
function summarizeUnchanged (
273
- token : 'category' | 'group' | 'audit' ,
307
+ token : string ,
274
308
{ changed, unchanged } : { changed : unknown [ ] ; unchanged : unknown [ ] } ,
275
309
) : string {
276
310
return [
0 commit comments