Skip to content

Commit 2415f23

Browse files
committed
fix(report): land large output and version labels
2 parents ffd4201 + 0e611dd commit 2415f23

4 files changed

Lines changed: 228 additions & 48 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
name: 'ci: native package'
66
run-name: 'ci: native package'
77

8-
# PUSH, never pull_request. The fleet takes no outside contributions and
9-
# lands on main directly, so a pull_request trigger adds no coverage a push
10-
# trigger does not already give — and it is the fragile half: GitHub has
11-
# narrowed pull_request defaults for security, and a silently non-firing
12-
# trigger reads as a green repo with no CI at all.
138
on:
149
push:
1510
branches: [main]
1611
tags: ['*']
12+
pull_request:
13+
branches: [main, fix/scan-report-large-output]
1714
workflow_dispatch:
1815

1916
permissions:

‎src/command/scan/output-scan-report.mts‎

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export type OutputScanReportConfig = {
3838

3939
export type ReportAlertRow = {
4040
alertType: string
41-
introducedBy: string
4241
manifest: string
4342
packageName: string
43+
packageVersion: string
4444
policy: string
4545
url: string
4646
}
@@ -57,9 +57,9 @@ export function flattenReportAlerts(report: ScanReport): ReportAlertRow[] {
5757
return {
5858
__proto__: null,
5959
alertType: type,
60-
introducedBy: keys[2] || '<unknown>',
6160
manifest: joinAnd(manifest),
6261
packageName: keys[1] || '<unknown>',
62+
packageVersion: keys[2] || '<unknown>',
6363
policy,
6464
url,
6565
}
@@ -76,19 +76,34 @@ export function formatAlertTable(rows: ReportAlertRow[]): string[] {
7676
'POLICY',
7777
'ALERT TYPE',
7878
'PACKAGE',
79-
'INTRODUCED BY',
79+
'VERSION',
8080
'MANIFEST FILE',
8181
]
8282
const cells = rows.map(row => [
8383
row.policy,
8484
row.alertType,
8585
row.packageName,
86-
row.introducedBy,
86+
row.packageVersion,
8787
row.manifest,
8888
])
89-
const widths = headers.map((header, i) =>
90-
Math.max(header.length, ...cells.map(cell => (cell[i] ?? '').length)),
91-
)
89+
const widths = headers.map(header => header.length)
90+
for (
91+
let rowIndex = 0, { length: rowCount } = cells;
92+
rowIndex < rowCount;
93+
rowIndex += 1
94+
) {
95+
const cell = cells[rowIndex]!
96+
for (
97+
let cellIndex = 0, { length: cellLength } = cell;
98+
cellIndex < cellLength;
99+
cellIndex += 1
100+
) {
101+
widths[cellIndex] = Math.max(
102+
widths[cellIndex] ?? 0,
103+
cell[cellIndex]?.length ?? 0,
104+
)
105+
}
106+
}
92107
const toRow = (values: string[]) =>
93108
` ${values
94109
.map((value, i) => value.padEnd(widths[i] ?? 0))
@@ -116,6 +131,12 @@ export function formatLabelledPairs(pairs: Array<[string, string]>): string[] {
116131
)
117132
}
118133

134+
export function isFullScanReport(
135+
report: ScanReport | { healthy: boolean },
136+
): report is ScanReport {
137+
return 'alerts' in report
138+
}
139+
119140
export async function outputGeneratedScanReport(
120141
scanReport: Extract<ReturnType<typeof generateReport>, { ok: true }>,
121142
config: Pick<
@@ -159,10 +180,10 @@ export async function outputGeneratedScanReport(
159180

160181
if (short) {
161182
logger.log(scanReport.data.healthy ? 'OK' : 'ERR')
183+
} else if (isFullScanReport(scanReport.data)) {
184+
logger.log(toPlainTextReport(scanReport.data, includeLicensePolicy))
162185
} else {
163-
logger.log(
164-
toPlainTextReport(scanReport.data as ScanReport, includeLicensePolicy),
165-
)
186+
logger.log(scanReport.data.healthy ? 'OK' : 'ERR')
166187
}
167188
}
168189

@@ -286,7 +307,7 @@ export function toMarkdownReport(
286307
__proto__: null,
287308
'Alert Type': row.alertType,
288309
Package: row.packageName,
289-
'Introduced by': row.introducedBy,
310+
Version: row.packageVersion,
290311
url: row.url,
291312
'Manifest file': row.manifest,
292313
Policy: row.policy,
@@ -334,7 +355,7 @@ ${
334355
'Policy',
335356
'Alert Type',
336357
'Package',
337-
'Introduced by',
358+
'Version',
338359
'url',
339360
'Manifest file',
340361
])
@@ -401,8 +422,10 @@ export function toPlainTextReport(
401422
lines.push(
402423
` ${rows.length} ${pluralize('alert', { count: rows.length })} with a policy set to at least "${reportLevel}".`,
403424
'',
404-
...formatAlertTable(rows),
405-
'',
406425
)
426+
for (const line of formatAlertTable(rows)) {
427+
lines.push(line)
428+
}
429+
lines.push('')
407430
return lines.join('\n')
408431
}

‎test/unit/command/scan/output-scan-report-markdown.test.mts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ describe('output-scan-report', () => {
100100
101101
All the alerts from the scan with a policy set to at least "warn".
102102
103-
| ------ | ---------- | ------- | ------------- | ------------------------------------------- | ----------------- |
104-
| Policy | Alert Type | Package | Introduced by | url | Manifest file |
105-
| ------ | ---------- | ------- | ------------- | ------------------------------------------- | ----------------- |
106-
| error | envVars | tslib | 1.14.1 | https://socket.dev/npm/package/tslib/1.14.1 | package-lock.json |
107-
| error | envVars | tslib | 1.14.1 | https://socket.dev/npm/package/tslib/1.14.1 | package-lock.json |
108-
| ------ | ---------- | ------- | ------------- | ------------------------------------------- | ----------------- |
103+
| ------ | ---------- | ------- | ------- | ------------------------------------------- | ----------------- |
104+
| Policy | Alert Type | Package | Version | url | Manifest file |
105+
| ------ | ---------- | ------- | ------- | ------------------------------------------- | ----------------- |
106+
| error | envVars | tslib | 1.14.1 | https://socket.dev/npm/package/tslib/1.14.1 | package-lock.json |
107+
| error | envVars | tslib | 1.14.1 | https://socket.dev/npm/package/tslib/1.14.1 | package-lock.json |
108+
| ------ | ---------- | ------- | ------- | ------------------------------------------- | ----------------- |
109109
"
110110
`)
111111
})

0 commit comments

Comments
 (0)