Skip to content

Commit c67ca3b

Browse files
committed
CI(diff): markdown table for PR review
1 parent 75251fa commit c67ca3b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/ci/check_lines.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ async function generateStats(root = 'src') {
2222
return files
2323
}
2424

25+
// biome-ignore lint/suspicious/noExplicitAny: it's okay for printing any data
26+
function printMarkdownTable(data: any[]) {
27+
if (!data.length) return 'No changes'
28+
const keys = Object.keys(data[0])
29+
console.log(`| ${keys.join(' | ')} |\n| ${keys.map(() => '---').join(' | ')} |`)
30+
console.log(data.map((row) => `| ${keys.map((key) => row[key]).join(' | ')} |`).join('\n'))
31+
}
32+
33+
const formatDiff = (count: number) => (count > 0 ? `+${count}` : count.toString())
34+
2535
function generateDiff(statsOld: FileStats[], statsNew: FileStats[]) {
2636
const results: FileStatsDiff[] = []
2737
const filesOld = new Set(statsOld.map((file) => file.path))
@@ -48,22 +58,24 @@ function generateDiff(statsOld: FileStats[], statsNew: FileStats[]) {
4858

4959
if (import.meta.main) {
5060
if (Bun.argv.length === 4) {
61+
// CI mode - compare two directories
5162
const [, , base, pr] = Bun.argv
5263
const baseStats = await generateStats(base)
5364
const prStats = await generateStats(pr)
5465
const diff = generateDiff(baseStats, prStats)
5566
diff.sort((a, b) => b.diff - a.diff)
67+
5668
console.log('## Changes:')
57-
console.log('```')
58-
console.table(diff)
69+
printMarkdownTable(diff.map((row) => ({ ...row, diff: formatDiff(row.diff) })))
70+
5971
const totalDiff = diff.reduce((sum, file) => sum + file.diff, 0)
6072
const total = prStats.reduce((sum, file) => sum + file.lines, 0)
61-
console.log(`\nTotal lines: ${total} (${totalDiff > 0 ? '+' : ''}${totalDiff})`)
62-
console.log('```')
73+
console.log(`\nTotal lines: ${total} (${formatDiff(totalDiff)})`)
6374
} else {
75+
// Regular mode - analyze a single directory
6476
const files = await generateStats(Bun.argv[2])
65-
6677
const top10 = files.slice(0, 10)
78+
6779
console.log('Top 10 files by lines:')
6880
console.table(top10)
6981

0 commit comments

Comments
 (0)