@@ -24,6 +24,8 @@ const shortenLabel = (itemKey) =>
24
24
: itemKey
25
25
26
26
const twoMB = 2 * 1024 * 1024
27
+ const ONE_HUNDRED_BYTES = 100
28
+ const ONE_HUNDRED_MS = 100
27
29
28
30
module . exports = async function addComment (
29
31
results = [ ] ,
@@ -82,24 +84,21 @@ module.exports = async function addComment(
82
84
// otherwise only show gzip values
83
85
else if ( ! isGzipItem && ! groupKey . match ( gzipIgnoreRegex ) ) return
84
86
85
- if (
86
- ! itemKey . startsWith ( 'buildDuration' ) ||
87
- ( isBenchmark && itemKey . match ( / r e q \/ s e c / ) )
88
- ) {
89
- if ( typeof mainItemVal === 'number' ) mainRepoTotal += mainItemVal
90
- if ( typeof diffItemVal === 'number' ) diffRepoTotal += diffItemVal
91
- }
92
-
93
87
// calculate the change
94
88
if ( mainItemVal !== diffItemVal ) {
95
89
if (
96
90
typeof mainItemVal === 'number' &&
97
91
typeof diffItemVal === 'number'
98
92
) {
99
- change = round ( diffItemVal - mainItemVal , 2 )
93
+ const roundedValue = round ( diffItemVal - mainItemVal , 2 )
100
94
101
95
// check if there is still a change after rounding
102
- if ( change !== 0 ) {
96
+ if (
97
+ roundedValue !== 0 &&
98
+ ( ( prettyType === 'ms' && roundedValue > ONE_HUNDRED_MS ) ||
99
+ ( prettyType === 'bytes' && roundedValue > ONE_HUNDRED_BYTES ) )
100
+ ) {
101
+ change = roundedValue
103
102
const absChange = Math . abs ( change )
104
103
const warnIfNegative = isBenchmark && itemKey . match ( / r e q \/ s e c / )
105
104
const warn = warnIfNegative
@@ -112,12 +111,22 @@ module.exports = async function addComment(
112
111
change = `${ warn } ${ change < 0 ? '-' : '+' } ${
113
112
useRawValue ? absChange : prettify ( absChange , prettyType )
114
113
} `
114
+ } else {
115
+ change = 'N/A'
115
116
}
116
117
} else {
117
118
change = 'N/A'
118
119
}
119
120
}
120
121
122
+ if (
123
+ ( change !== 'N/A' && ! itemKey . startsWith ( 'buildDuration' ) ) ||
124
+ ( isBenchmark && itemKey . match ( / r e q \/ s e c / ) )
125
+ ) {
126
+ if ( typeof mainItemVal === 'number' ) mainRepoTotal += mainItemVal
127
+ if ( typeof diffItemVal === 'number' ) diffRepoTotal += diffItemVal
128
+ }
129
+
121
130
groupTable += `| ${
122
131
isBenchmark ? itemKey : shortenLabel ( itemKey )
123
132
} | ${ mainItemStr } | ${ diffItemStr } | ${ change } |\n`
@@ -169,8 +178,7 @@ module.exports = async function addComment(
169
178
170
179
// add diffs
171
180
if ( result . diffs ) {
172
- const diffHeading = '#### Diffs\n'
173
- let diffContent = diffHeading
181
+ let diffContent = ''
174
182
175
183
Object . keys ( result . diffs ) . forEach ( ( itemKey ) => {
176
184
const curDiff = result . diffs [ itemKey ]
@@ -187,8 +195,11 @@ module.exports = async function addComment(
187
195
diffContent += `\n</details>\n`
188
196
} )
189
197
190
- if ( diffContent !== diffHeading ) {
198
+ if ( diffContent . length > 0 ) {
199
+ resultContent += `<details>\n`
200
+ resultContent += `<summary><strong>Diff details</strong></summary>\n\n`
191
201
resultContent += diffContent
202
+ resultContent += `\n</details>\n\n`
192
203
}
193
204
}
194
205
let increaseDecreaseNote = ''
@@ -199,7 +210,7 @@ module.exports = async function addComment(
199
210
increaseDecreaseNote = ' (Decrease detected ✓)'
200
211
}
201
212
202
- comment += `<details>\n`
213
+ comment += `<details ${ results . length === 1 ? 'open' : '' } >\n`
203
214
comment += `<summary><strong>${ result . title } </strong>${ increaseDecreaseNote } </summary>\n\n<br/>\n\n`
204
215
comment += resultContent
205
216
comment += '</details>\n'
0 commit comments