Skip to content

Commit d3e2739

Browse files
author
Pelle Wessman
committed
Use health status from API to determine success
1 parent 0d36c6d commit d3e2739

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ socket report view QXU8PmK7LfH608RAwfIKdbcHgwEd_ZeWJ9QEGv05FJUQ
4848
## Strictness flags
4949

5050
* `--all` - by default only `high` and `critical` issues are included, by setting this flag all issues will be included
51-
* `--strict` - when set, exits with an error code if any issues were found
51+
* `--strict` - when set, exits with an error code if report result is deemed unhealthy
5252

5353
### Other flags
5454

lib/commands/report/view.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js'
99
import { InputError } from '../../utils/errors.js'
1010
import { getSeverityCount, formatSeverityCount } from '../../utils/format-issues.js'
1111
import { printFlagList } from '../../utils/formatting.js'
12-
import { objectSome } from '../../utils/misc.js'
1312
import { setupSdk } from '../../utils/sdk.js'
1413

1514
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand} */
@@ -56,7 +55,7 @@ function setupCommand (name, description, argv, importMeta) {
5655
'--all': 'Include all issues',
5756
'--json': 'Output result as json',
5857
'--markdown': 'Output result as markdown',
59-
'--strict': 'Exits with an error code if any matching issues are found',
58+
'--strict': 'Exits with an error code if report result is deemed unhealthy',
6059
}, 6)}
6160
6261
Examples
@@ -119,9 +118,7 @@ function setupCommand (name, description, argv, importMeta) {
119118
}
120119

121120
/**
122-
* @typedef ReportData
123-
* @property {import('@socketsecurity/sdk').SocketSdkReturnType<'getReport'>["data"]} data
124-
* @property {Record<import('../../utils/format-issues').SocketIssue['severity'], number>} severityCount
121+
* @typedef {import('@socketsecurity/sdk').SocketSdkReturnType<'getReport'>["data"]} ReportData
125122
*/
126123

127124
/**
@@ -142,27 +139,29 @@ export async function fetchReportData (reportId, { includeAllIssues, strict }) {
142139

143140
// Conclude the status of the API call
144141

145-
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high')
146-
147-
if (objectSome(severityCount)) {
142+
if (strict) {
143+
if (result.data.healthy) {
144+
spinner.succeed('Report result is healthy and great!')
145+
} else {
146+
spinner.fail('Report result deemed unhealthy for project')
147+
}
148+
} else if (result.data.healthy === false) {
149+
const severityCount = getSeverityCount(result.data.issues, includeAllIssues ? undefined : 'high')
148150
const issueSummary = formatSeverityCount(severityCount)
149-
spinner[strict ? 'fail' : 'succeed'](`Report has these issues: ${issueSummary}`)
151+
spinner.succeed(`Report has these issues: ${issueSummary}`)
150152
} else {
151153
spinner.succeed('Report has no issues')
152154
}
153155

154-
return {
155-
data: result.data,
156-
severityCount,
157-
}
156+
return result.data
158157
}
159158

160159
/**
161-
* @param {ReportData} reportData
160+
* @param {ReportData} data
162161
* @param {{ name: string } & CommandContext} context
163162
* @returns {void}
164163
*/
165-
export function formatReportDataOutput ({ data, severityCount }, { name, outputJson, outputMarkdown, reportId, strict }) {
164+
export function formatReportDataOutput (data, { name, outputJson, outputMarkdown, reportId, strict }) {
166165
if (outputJson) {
167166
console.log(JSON.stringify(data, undefined, 2))
168167
} else {
@@ -175,7 +174,7 @@ export function formatReportDataOutput ({ data, severityCount }, { name, outputJ
175174
}
176175
}
177176

178-
if (strict && objectSome(severityCount)) {
177+
if (strict && data.healthy === false) {
179178
process.exit(1)
180179
}
181180
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"dependencies": {
7777
"@apideck/better-ajv-errors": "^0.3.6",
7878
"@socketsecurity/config": "^2.0.0",
79-
"@socketsecurity/sdk": "^0.5.0",
79+
"@socketsecurity/sdk": "^0.5.1",
8080
"chalk": "^5.1.2",
8181
"globby": "^13.1.3",
8282
"hpagent": "^1.2.0",

0 commit comments

Comments
 (0)