Skip to content

Commit 9d10182

Browse files
Merge pull request #827 from ebickle/fix/comment-warn-only
fix: add summary comment on failure when warn-only: true
2 parents 9192be9 + fb86db2 commit 9d10182

File tree

7 files changed

+2381
-1621
lines changed

7 files changed

+2381
-1621
lines changed

dist/index.js

Lines changed: 2315 additions & 1592 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/licenses.txt

Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sourcemap-register.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/comment-pr.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ const COMMENT_MARKER = '<!-- dependency-review-pr-comment-marker -->'
1717

1818
export async function commentPr(
1919
commentContent: string,
20-
config: ConfigurationOptions
20+
config: ConfigurationOptions,
21+
issueFound: boolean
2122
): Promise<void> {
2223
if (
2324
!(
2425
config.comment_summary_in_pr === 'always' ||
25-
(config.comment_summary_in_pr === 'on-failure' &&
26-
process.exitCode === core.ExitCode.Failure)
26+
(config.comment_summary_in_pr === 'on-failure' && issueFound)
2727
)
2828
) {
2929
return

src/deny.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,6 @@ export async function getDeniedChanges(
3535
}
3636
}
3737

38-
if (hasDeniedPackage) {
39-
core.setFailed('Dependency review detected denied packages.')
40-
} else {
41-
core.info('Dependency review did not detect any denied packages')
42-
}
43-
4438
return changesDenied
4539
}
4640

src/main.ts

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

144+
let issueFound = false
145+
144146
if (config.vulnerability_check) {
145147
core.setOutput('vulnerable-changes', JSON.stringify(vulnerableChanges))
146148
summary.addChangeVulnerabilitiesToSummary(vulnerableChanges, minSeverity)
147-
printVulnerabilitiesBlock(vulnerableChanges, minSeverity, warnOnly)
149+
issueFound ||= await printVulnerabilitiesBlock(
150+
vulnerableChanges,
151+
minSeverity,
152+
warnOnly
153+
)
148154
}
149155
if (config.license_check) {
150156
core.setOutput(
151157
'invalid-license-changes',
152158
JSON.stringify(invalidLicenseChanges)
153159
)
154160
summary.addLicensesToSummary(invalidLicenseChanges, config)
155-
printLicensesBlock(invalidLicenseChanges, warnOnly)
161+
issueFound ||= await printLicensesBlock(invalidLicenseChanges, warnOnly)
156162
}
157163
if (config.deny_packages || config.deny_groups) {
158164
core.setOutput('denied-changes', JSON.stringify(deniedChanges))
159165
summary.addDeniedToSummary(deniedChanges)
160-
printDeniedDependencies(deniedChanges, config)
166+
issueFound ||= await printDeniedDependencies(deniedChanges, config)
161167
}
162168
if (config.show_openssf_scorecard) {
163169
summary.addScorecardToSummary(scorecard, config)
@@ -182,7 +188,7 @@ async function run(): Promise<void> {
182188
}
183189

184190
// update the PR comment if needed with the right-sized summary
185-
await commentPr(rendered, config)
191+
await commentPr(rendered, config, issueFound)
186192
} catch (error) {
187193
if (error instanceof RequestError && error.status === 404) {
188194
core.setFailed(
@@ -208,14 +214,12 @@ function printVulnerabilitiesBlock(
208214
addedChanges: Changes,
209215
minSeverity: Severity,
210216
warnOnly: boolean
211-
): void {
212-
let vulFound = false
213-
core.group('Vulnerabilities', async () => {
214-
if (addedChanges.length > 0) {
215-
for (const change of addedChanges) {
216-
printChangeVulnerabilities(change)
217-
}
218-
vulFound = true
217+
): Promise<boolean> {
218+
return core.group('Vulnerabilities', async () => {
219+
let vulFound = false
220+
221+
for (const change of addedChanges) {
222+
vulFound ||= printChangeVulnerabilities(change)
219223
}
220224

221225
if (vulFound) {
@@ -230,10 +234,12 @@ function printVulnerabilitiesBlock(
230234
`Dependency review did not detect any vulnerable packages with severity level "${minSeverity}" or higher.`
231235
)
232236
}
237+
238+
return vulFound
233239
})
234240
}
235241

236-
function printChangeVulnerabilities(change: Change): void {
242+
function printChangeVulnerabilities(change: Change): boolean {
237243
for (const vuln of change.vulnerabilities) {
238244
core.info(
239245
`${styles.bold.open}${change.manifest} » ${change.name}@${
@@ -244,14 +250,18 @@ function printChangeVulnerabilities(change: Change): void {
244250
)
245251
core.info(` ↪ ${vuln.advisory_url}`)
246252
}
253+
return change.vulnerabilities.length > 0
247254
}
248255

249256
function printLicensesBlock(
250257
invalidLicenseChanges: Record<string, Changes>,
251258
warnOnly: boolean
252-
): void {
253-
core.group('Licenses', async () => {
259+
): Promise<boolean> {
260+
return core.group('Licenses', async () => {
261+
let issueFound = false
262+
254263
if (invalidLicenseChanges.forbidden.length > 0) {
264+
issueFound = true
255265
core.info('\nThe following dependencies have incompatible licenses:')
256266
printLicensesError(invalidLicenseChanges.forbidden)
257267
const msg = 'Dependency review detected incompatible licenses.'
@@ -262,6 +272,7 @@ function printLicensesBlock(
262272
}
263273
}
264274
if (invalidLicenseChanges.unresolved.length > 0) {
275+
issueFound = true
265276
core.warning(
266277
'\nThe validity of the licenses of the dependencies below could not be determined. Ensure that they are valid SPDX licenses:'
267278
)
@@ -271,6 +282,8 @@ function printLicensesBlock(
271282
)
272283
}
273284
printNullLicenses(invalidLicenseChanges.unlicensed)
285+
286+
return issueFound
274287
})
275288
}
276289

@@ -373,8 +386,10 @@ function printScannedDependencies(changes: Changes): void {
373386
function printDeniedDependencies(
374387
changes: Changes,
375388
config: ConfigurationOptions
376-
): void {
377-
core.group('Denied', async () => {
389+
): Promise<boolean> {
390+
return core.group('Denied', async () => {
391+
let issueFound = false
392+
378393
for (const denied of config.deny_packages) {
379394
core.info(`Config: ${denied}`)
380395
}
@@ -383,6 +398,15 @@ function printDeniedDependencies(
383398
core.info(`Change: ${change.name}@${change.version} is denied`)
384399
core.info(`Change: ${change.package_url} is denied`)
385400
}
401+
402+
if (changes.length > 0) {
403+
issueFound = true
404+
core.setFailed('Dependency review detected denied packages.')
405+
} else {
406+
core.info('Dependency review did not detect any denied packages')
407+
}
408+
409+
return issueFound
386410
})
387411
}
388412

0 commit comments

Comments
 (0)