Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,7 @@
!/src/commands/scan/diff-scan-verdict.test.mts
!/src/commands/scan/notifications/
!/src/commands/scan/notifications/report.mts
!/src/commands/scan/notifications/report.test.mts
!/src/commands/scan/notifications/slack-bot.mts
!/src/commands/scan/notifications/slack-bot.test.mts
!/src/commands/scan/notifications/slack-webhook.mts
Expand Down
6 changes: 6 additions & 0 deletions docs/commands/scan/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ filters:
Delivery errors are reported as warnings and do not change the scan decision.
Existing report viewing commands do not send notifications.

When the scan creation flow runs with `--reach`, Slack findings include the
matching reachability state and a bounded call trace for confirmed reachable
findings. Unknown or malformed facts are marked unclassified. Set
`reachability_alerts_only: true` on a destination to send only findings whose
facts confirm they are reachable.

Slack bot delivery is available when the job also supplies a bot token and
channel configuration. Create a Slack app with the `chat:write` bot token scope,
install it in the workspace, and invite it to each target channel. Keep the bot
Expand Down
36 changes: 34 additions & 2 deletions src/commands/scan/handle-create-new-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.m
import { finalizeTier1Scan } from './finalize-tier1-scan.mts'
import { handlePrDiffScan } from './handle-diff-scan.mts'
import { handleScanReport } from './handle-scan-report.mts'
import { isSlackNotificationConfigured } from './notifications/slack-webhook.mts'
import { outputCreateNewScan } from './output-create-new-scan.mts'
import { performReachabilityAnalysis } from './perform-reachability-analysis.mts'
import {
Expand Down Expand Up @@ -576,6 +577,27 @@ async function createNewScan(

// A scan without --reach would upload a leftover report as an SBOM with
// stale reachability results; a failed scan keeps it for debugging.
const reachabilityEnabled =
reach.runReachabilityAnalysis && !reachabilityFallback
let notificationReachabilityFacts: unknown
if (
report &&
fullScanCResult.ok &&
reachabilityEnabled &&
reachabilityReport &&
isSlackNotificationConfigured()
) {
try {
notificationReachabilityFacts = JSON.parse(
await fs.readFile(path.resolve(cwd, reachabilityReport), 'utf8'),
) as unknown
} catch {
logger.warn(
'Reachability facts could not be read for Slack notifications; findings will be marked unclassified.',
)
}
}

if (
fullScanCResult.ok &&
scanId &&
Expand Down Expand Up @@ -604,7 +626,12 @@ async function createNewScan(
outputKind,
pythonJsonFormat,
pythonJsonContext,
notificationContext: { repository: repoName, branch: branchName },
notificationContext: {
repository: repoName,
branch: branchName,
reachabilityEnabled,
reachabilityFacts: notificationReachabilityFacts,
},
})
} else {
await handleScanReport({
Expand All @@ -616,7 +643,12 @@ async function createNewScan(
reportLevel,
scanId,
short: false,
notificationContext: { repository: repoName, branch: branchName },
notificationContext: {
repository: repoName,
branch: branchName,
reachabilityEnabled,
reachabilityFacts: notificationReachabilityFacts,
},
})
}
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/commands/scan/handle-diff-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getDiffScanVerdict } from './diff-scan-verdict.mts'
import { fetchDiffScan } from './fetch-diff-scan.mts'
import { outputDiffScan } from './output-diff-scan.mts'

import type { NotificationMetadata } from './notifications/report.mts'
import type { PythonDiffJsonContext } from './python-diff-json.mts'
import type { OutputKind } from '../../types.mts'

Expand Down Expand Up @@ -68,9 +69,7 @@ export async function handlePrDiffScan({
outputKind: OutputKind
pythonJsonFormat?: boolean | undefined
pythonJsonContext?: PythonDiffJsonContext | undefined
notificationContext?:
| { repository?: string | undefined; branch?: string | undefined }
| undefined
notificationContext?: NotificationMetadata | undefined
}): Promise<void> {
const result = await fetchDiffScan({ id1, id2, orgSlug })
await outputDiffScan(result, {
Expand Down
Loading
Loading