Skip to content

Commit 1abc411

Browse files
committed
feat(python-cli-parity): include reachability in Slack notifications
1 parent 0899338 commit 1abc411

10 files changed

Lines changed: 739 additions & 21 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@
893893
!/src/commands/scan/diff-scan-verdict.test.mts
894894
!/src/commands/scan/notifications/
895895
!/src/commands/scan/notifications/report.mts
896+
!/src/commands/scan/notifications/report.test.mts
896897
!/src/commands/scan/notifications/slack-bot.mts
897898
!/src/commands/scan/notifications/slack-bot.test.mts
898899
!/src/commands/scan/notifications/slack-webhook.mts

‎docs/commands/scan/report.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ filters:
6767
Delivery errors are reported as warnings and do not change the scan decision.
6868
Existing report viewing commands do not send notifications.
6969

70+
When the scan creation flow runs with `--reach`, Slack findings include the
71+
matching reachability state and a bounded call trace for confirmed reachable
72+
findings. Unknown or malformed facts are marked unclassified. Set
73+
`reachability_alerts_only: true` on a destination to send only findings whose
74+
facts confirm they are reachable.
75+
7076
Slack bot delivery is available when the job also supplies a bot token and
7177
channel configuration. Create a Slack app with the `chat:write` bot token scope,
7278
install it in the workspace, and invite it to each target channel. Keep the bot

‎src/commands/scan/handle-create-new-scan.mts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { fetchSupportedScanFileNames } from './fetch-supported-scan-file-names.m
99
import { finalizeTier1Scan } from './finalize-tier1-scan.mts'
1010
import { handlePrDiffScan } from './handle-diff-scan.mts'
1111
import { handleScanReport } from './handle-scan-report.mts'
12+
import { isSlackNotificationConfigured } from './notifications/slack-webhook.mts'
1213
import { outputCreateNewScan } from './output-create-new-scan.mts'
1314
import { performReachabilityAnalysis } from './perform-reachability-analysis.mts'
1415
import {
@@ -576,6 +577,27 @@ async function createNewScan(
576577

577578
// A scan without --reach would upload a leftover report as an SBOM with
578579
// stale reachability results; a failed scan keeps it for debugging.
580+
const reachabilityEnabled =
581+
reach.runReachabilityAnalysis && !reachabilityFallback
582+
let notificationReachabilityFacts: unknown
583+
if (
584+
report &&
585+
fullScanCResult.ok &&
586+
reachabilityEnabled &&
587+
reachabilityReport &&
588+
isSlackNotificationConfigured()
589+
) {
590+
try {
591+
notificationReachabilityFacts = JSON.parse(
592+
await fs.readFile(path.resolve(cwd, reachabilityReport), 'utf8'),
593+
) as unknown
594+
} catch {
595+
logger.warn(
596+
'Reachability facts could not be read for Slack notifications; findings will be marked unclassified.',
597+
)
598+
}
599+
}
600+
579601
if (
580602
fullScanCResult.ok &&
581603
scanId &&
@@ -604,7 +626,12 @@ async function createNewScan(
604626
outputKind,
605627
pythonJsonFormat,
606628
pythonJsonContext,
607-
notificationContext: { repository: repoName, branch: branchName },
629+
notificationContext: {
630+
repository: repoName,
631+
branch: branchName,
632+
reachabilityEnabled,
633+
reachabilityFacts: notificationReachabilityFacts,
634+
},
608635
})
609636
} else {
610637
await handleScanReport({
@@ -616,7 +643,12 @@ async function createNewScan(
616643
reportLevel,
617644
scanId,
618645
short: false,
619-
notificationContext: { repository: repoName, branch: branchName },
646+
notificationContext: {
647+
repository: repoName,
648+
branch: branchName,
649+
reachabilityEnabled,
650+
reachabilityFacts: notificationReachabilityFacts,
651+
},
620652
})
621653
}
622654
} else {

‎src/commands/scan/handle-diff-scan.mts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getDiffScanVerdict } from './diff-scan-verdict.mts'
22
import { fetchDiffScan } from './fetch-diff-scan.mts'
33
import { outputDiffScan } from './output-diff-scan.mts'
44

5+
import type { NotificationMetadata } from './notifications/report.mts'
56
import type { PythonDiffJsonContext } from './python-diff-json.mts'
67
import type { OutputKind } from '../../types.mts'
78

@@ -68,9 +69,7 @@ export async function handlePrDiffScan({
6869
outputKind: OutputKind
6970
pythonJsonFormat?: boolean | undefined
7071
pythonJsonContext?: PythonDiffJsonContext | undefined
71-
notificationContext?:
72-
| { repository?: string | undefined; branch?: string | undefined }
73-
| undefined
72+
notificationContext?: NotificationMetadata | undefined
7473
}): Promise<void> {
7574
const result = await fetchDiffScan({ id1, id2, orgSlug })
7675
await outputDiffScan(result, {

0 commit comments

Comments
 (0)