Skip to content

Commit 0a198ab

Browse files
committed
fix: replace integer failureCount with boolean
1 parent fc499fc commit 0a198ab

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

src/comment-pr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const COMMENT_MARKER = '<!-- dependency-review-pr-comment-marker -->'
1818
export async function commentPr(
1919
commentContent: string,
2020
config: ConfigurationOptions,
21-
failureCount: number
21+
issueFound: boolean
2222
): Promise<void> {
2323
if (
2424
!(
2525
config.comment_summary_in_pr === 'always' ||
26-
(config.comment_summary_in_pr === 'on-failure' && failureCount > 0)
26+
(config.comment_summary_in_pr === 'on-failure' && issueFound)
2727
)
2828
) {
2929
return

src/main.ts

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,29 @@ async function run(): Promise<void> {
141141
summary.addSnapshotWarnings(config, snapshot_warnings)
142142
}
143143

144-
let failureCount = 0;
144+
let issueFound = false
145145

146146
if (config.vulnerability_check) {
147147
core.setOutput('vulnerable-changes', JSON.stringify(vulnerableChanges))
148148
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity)
149-
failureCount += printVulnerabilitiesBlock(vulnerableChanges, minSeverity, warnOnly)
149+
issueFound ||= printVulnerabilitiesBlock(
150+
vulnerableChanges,
151+
minSeverity,
152+
warnOnly
153+
)
150154
}
151155
if (config.license_check) {
152156
core.setOutput(
153157
'invalid-license-changes',
154158
JSON.stringify(invalidLicenseChanges)
155159
)
156160
summary.addLicensesToSummary(invalidLicenseChanges, config)
157-
failureCount += printLicensesBlock(invalidLicenseChanges, warnOnly)
161+
issueFound ||= printLicensesBlock(invalidLicenseChanges, warnOnly)
158162
}
159163
if (config.deny_packages || config.deny_groups) {
160164
core.setOutput('denied-changes', JSON.stringify(deniedChanges))
161165
summary.addDeniedToSummary(deniedChanges)
162-
failureCount += printDeniedDependencies(deniedChanges, config)
166+
issueFound ||= printDeniedDependencies(deniedChanges, config)
163167
}
164168
if (config.show_openssf_scorecard) {
165169
summary.addScorecardToSummary(scorecard, config)
@@ -184,7 +188,7 @@ async function run(): Promise<void> {
184188
}
185189

186190
// update the PR comment if needed with the right-sized summary
187-
await commentPr(rendered, config, failureCount)
191+
await commentPr(rendered, config, issueFound)
188192
} catch (error) {
189193
if (error instanceof RequestError && error.status === 404) {
190194
core.setFailed(
@@ -210,17 +214,14 @@ function printVulnerabilitiesBlock(
210214
addedChanges: Changes,
211215
minSeverity: Severity,
212216
warnOnly: boolean
213-
): number {
214-
let vulCount = 0
217+
): boolean {
218+
let vulFound = false
215219
core.group('Vulnerabilities', async () => {
216-
if (addedChanges.length > 0) {
217-
for (const change of addedChanges) {
218-
printChangeVulnerabilities(change)
219-
vulCount += change.vulnerabilities.length;
220-
}
220+
for (const change of addedChanges) {
221+
vulFound ||= printChangeVulnerabilities(change)
221222
}
222223

223-
if (vulCount > 0) {
224+
if (vulFound) {
224225
const msg = 'Dependency review detected vulnerable packages.'
225226
if (warnOnly) {
226227
core.warning(msg)
@@ -233,10 +234,10 @@ function printVulnerabilitiesBlock(
233234
)
234235
}
235236
})
236-
return vulCount
237+
return vulFound
237238
}
238239

239-
function printChangeVulnerabilities(change: Change): void {
240+
function printChangeVulnerabilities(change: Change): boolean {
240241
for (const vuln of change.vulnerabilities) {
241242
core.info(
242243
`${styles.bold.open}${change.manifest} » ${change.name}@${
@@ -247,16 +248,17 @@ function printChangeVulnerabilities(change: Change): void {
247248
)
248249
core.info(` ↪ ${vuln.advisory_url}`)
249250
}
251+
return change.vulnerabilities.length > 0
250252
}
251253

252254
function printLicensesBlock(
253255
invalidLicenseChanges: Record<string, Changes>,
254256
warnOnly: boolean
255-
): number {
256-
let failureCount = 0;
257+
): boolean {
258+
let issueFound = false
257259
core.group('Licenses', async () => {
258260
if (invalidLicenseChanges.forbidden.length > 0) {
259-
failureCount += invalidLicenseChanges.forbidden.length;
261+
issueFound = true
260262
core.info('\nThe following dependencies have incompatible licenses:')
261263
printLicensesError(invalidLicenseChanges.forbidden)
262264
const msg = 'Dependency review detected incompatible licenses.'
@@ -267,7 +269,7 @@ function printLicensesBlock(
267269
}
268270
}
269271
if (invalidLicenseChanges.unresolved.length > 0) {
270-
failureCount += invalidLicenseChanges.unresolved.length;
272+
issueFound = true
271273
core.warning(
272274
'\nThe validity of the licenses of the dependencies below could not be determined. Ensure that they are valid SPDX licenses:'
273275
)
@@ -278,7 +280,7 @@ function printLicensesBlock(
278280
}
279281
printNullLicenses(invalidLicenseChanges.unlicensed)
280282
})
281-
return failureCount;
283+
return issueFound
282284
}
283285

284286
function printLicensesError(changes: Changes): void {
@@ -380,7 +382,8 @@ function printScannedDependencies(changes: Changes): void {
380382
function printDeniedDependencies(
381383
changes: Changes,
382384
config: ConfigurationOptions
383-
): number {
385+
): boolean {
386+
let issueFound = false
384387
core.group('Denied', async () => {
385388
for (const denied of config.deny_packages) {
386389
core.info(`Config: ${denied}`)
@@ -392,12 +395,13 @@ function printDeniedDependencies(
392395
}
393396

394397
if (changes.length > 0) {
398+
issueFound = true
395399
core.setFailed('Dependency review detected denied packages.')
396400
} else {
397401
core.info('Dependency review did not detect any denied packages')
398402
}
399403
})
400-
return changes.length
404+
return issueFound
401405
}
402406

403407
function getScorecardChanges(changes: Changes): Changes {

0 commit comments

Comments
 (0)