@@ -9,7 +9,6 @@ import { ChalkOrMarkdown } from '../../utils/chalk-markdown.js'
9
9
import { InputError } from '../../utils/errors.js'
10
10
import { getSeverityCount , formatSeverityCount } from '../../utils/format-issues.js'
11
11
import { printFlagList } from '../../utils/formatting.js'
12
- import { objectSome } from '../../utils/misc.js'
13
12
import { setupSdk } from '../../utils/sdk.js'
14
13
15
14
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand } */
@@ -56,7 +55,7 @@ function setupCommand (name, description, argv, importMeta) {
56
55
'--all' : 'Include all issues' ,
57
56
'--json' : 'Output result as json' ,
58
57
'--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 ' ,
60
59
} , 6 ) }
61
60
62
61
Examples
@@ -119,9 +118,7 @@ function setupCommand (name, description, argv, importMeta) {
119
118
}
120
119
121
120
/**
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
125
122
*/
126
123
127
124
/**
@@ -142,27 +139,29 @@ export async function fetchReportData (reportId, { includeAllIssues, strict }) {
142
139
143
140
// Conclude the status of the API call
144
141
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' )
148
150
const issueSummary = formatSeverityCount ( severityCount )
149
- spinner [ strict ? 'fail' : ' succeed' ] ( `Report has these issues: ${ issueSummary } ` )
151
+ spinner . succeed ( `Report has these issues: ${ issueSummary } ` )
150
152
} else {
151
153
spinner . succeed ( 'Report has no issues' )
152
154
}
153
155
154
- return {
155
- data : result . data ,
156
- severityCount,
157
- }
156
+ return result . data
158
157
}
159
158
160
159
/**
161
- * @param {ReportData } reportData
160
+ * @param {ReportData } data
162
161
* @param {{ name: string } & CommandContext } context
163
162
* @returns {void }
164
163
*/
165
- export function formatReportDataOutput ( { data, severityCount } , { name, outputJson, outputMarkdown, reportId, strict } ) {
164
+ export function formatReportDataOutput ( data , { name, outputJson, outputMarkdown, reportId, strict } ) {
166
165
if ( outputJson ) {
167
166
console . log ( JSON . stringify ( data , undefined , 2 ) )
168
167
} else {
@@ -175,7 +174,7 @@ export function formatReportDataOutput ({ data, severityCount }, { name, outputJ
175
174
}
176
175
}
177
176
178
- if ( strict && objectSome ( severityCount ) ) {
177
+ if ( strict && data . healthy === false ) {
179
178
process . exit ( 1 )
180
179
}
181
180
}
0 commit comments