Skip to content

Commit 5243123

Browse files
authored
chore(ci): correct data formatting for diff comment (#2345)
1 parent c6fa9e5 commit 5243123

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

.github/actions/file-diff/index.js

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,33 +149,31 @@ async function run() {
149149
]
150150
: []),
151151
],
152-
...fileMap.entries(),
153-
]
154-
.reduce(
155-
(
156-
table,
157-
[readableFilename, { byteSize = 0, diffByteSize = 0 }]
158-
) => {
159-
// @todo readable filename can be linked to html diff of the file?
160-
// https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6
161-
const row = [
162-
readableFilename,
163-
byteSize === 0 ? "**removed**" : bytesToSize(byteSize),
164-
diffByteSize === 0 ? "" : bytesToSize(diffByteSize),
165-
];
166-
167-
if (hasDiff && diffByteSize > 0) {
168-
if (byteSize === 0) row.push("", "");
169-
else {
170-
row.push(printChange(diffByteSize - byteSize), "");
171-
}
152+
].map((row) => `| ${row.join(" | ")} |`),
153+
...fileMap.entries().reduce(
154+
(
155+
table,
156+
[readableFilename, { byteSize = 0, diffByteSize = 0 }]
157+
) => {
158+
// @todo readable filename can be linked to html diff of the file?
159+
// https://github.com/adobe/spectrum-css/pull/2093/files#diff-6badd53e481452b5af234953767029ef2e364427dd84cdeed25f5778b6fca2e6
160+
const row = [
161+
readableFilename,
162+
byteSize === 0 ? "**removed**" : bytesToSize(byteSize),
163+
diffByteSize === 0 ? "" : bytesToSize(diffByteSize),
164+
];
165+
166+
if (hasDiff && diffByteSize > 0) {
167+
if (byteSize === 0) row.push("", "");
168+
else {
169+
row.push(printChange(diffByteSize - byteSize), "");
172170
}
171+
}
173172

174-
return [...table, row];
175-
},
176-
[]
177-
)
178-
.map((row) => `| ${row.join(" | ")} |`),
173+
return [...table, row];
174+
},
175+
[]
176+
).map((row) => `| ${row.join(" | ")} |`),
179177
);
180178

181179
markdown.push(...md);

.github/actions/file-diff/utilities.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ function debugEmptyDirectory(path, pattern, { core }) {
6262
* @returns {string} The size in human readable format
6363
*/
6464
exports.bytesToSize = function (bytes) {
65+
if (!bytes) return "-";
6566
if (bytes === 0) return "0";
6667

6768
const sizes = ["bytes", "KB", "MB", "GB", "TB"];
69+
6870
// Determine the size identifier to use (KB, MB, etc)
6971
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
70-
if (i === 0) return (bytes / 1000).toFixed(2) + " " + sizes[1];
72+
73+
if (i === 0) {
74+
const value = (bytes / 1000).toFixed(2);
75+
if (value === "0.00") return "< 0.01 KB";
76+
return value + " " + sizes[1];
77+
}
78+
7179
return (bytes / Math.pow(1024, i)).toFixed(2) + " " + sizes[i];
7280
};
7381

0 commit comments

Comments
 (0)