Skip to content

Commit cd5a112

Browse files
committed
feat(python-cli-parity): document managed and per-run notifications
1 parent 6b14ee3 commit cd5a112

3 files changed

Lines changed: 129 additions & 29 deletions

File tree

‎docs/commands/scan/report.md‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ or policy-level filtering is applied.
3535

3636
## Slack CI notifications
3737

38-
The scan creation report flow can send an opt-in Slack summary after it evaluates
39-
the report. Store the webhook URL in your CI secret store and expose the JSON
40-
configuration only to trusted jobs:
38+
The scan creation and diff report flows can send an opt-in Slack summary after
39+
they evaluate the report. Store the webhook URL in your CI secret store and
40+
expose the JSON configuration only to trusted jobs:
4141

4242
```sh
4343
export SOCKET_SLACK_CONFIG_JSON='{"url":"https://hooks.slack.com/services/..."}'
@@ -90,15 +90,15 @@ printing the token or changing the scan decision.
9090

9191
## Jira CI tasks
9292

93-
The scan creation report flow can create one Jira Task per report with findings.
94-
Reruns for the same repository, branch, pull request, and commit update the
95-
existing task. Store the API token in your CI secret store and enable Jira only
96-
for trusted jobs:
93+
The scan creation and diff report flows can create one Jira Task per report with
94+
findings. Reruns for the same repository, branch, pull request, and commit
95+
update the existing task. Store the API token in your CI secret store and
96+
enable Jira only for trusted jobs:
9797

9898
```sh
9999
export SOCKET_JIRA_ENABLED=true
100100
# Set SOCKET_JIRA_CONFIG_JSON from your CI secret store.
101-
socket ci
101+
socket scan create --report
102102
```
103103

104104
Store a JSON value like this in `SOCKET_JIRA_CONFIG_JSON`:
@@ -111,3 +111,19 @@ Store a JSON value like this in `SOCKET_JIRA_CONFIG_JSON`:
111111
email, an API token, and a Jira project key. Notifications include the Socket
112112
report link, package, alert, source, and manifest details. Jira lookup or
113113
delivery failures are reported as warnings and do not change the scan result.
114+
115+
## Managed integrations and per-run notifications
116+
117+
Socket managed organization notifications track alert lifecycle events such as
118+
alert creation, changes, and clearing. Managed Slack webhooks are sent
119+
immediately, managed email is batched, and managed Jira creates tickets for
120+
alert lifecycle changes. The CI notifications above instead summarize findings
121+
from an individual CLI scan report: Slack can send that run to incoming webhooks
122+
or bot channels, and Jira creates or updates one task for the repository,
123+
branch, pull request, and commit.
124+
125+
These delivery paths can overlap. A default-branch CI scan may report a finding
126+
that also causes a managed alert notification. Enable the per-run settings only
127+
for CI jobs that need scan-level summaries, and configure the Jira and Slack
128+
credentials in trusted CI secret storage. Managed notification settings remain
129+
configured in Socket organization integrations.

‎src/commands/scan/notifications/dispatch.mts‎

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
1+
import { logger } from '../../../utils/logger.mts'
12
import { isJiraEnabled, sendJiraTaskNotification } from './jira.mts'
3+
import type { NotificationReport } from './report.mts'
24
import { sendSlackBotNotifications } from './slack-bot.mts'
35
import {
46
getSlackNotificationConfig,
5-
isSlackNotificationConfigured,
7+
isSlackWebhookConfigured,
68
sendSlackWebhookNotifications,
79
} from './slack-webhook.mts'
8-
import { logger } from '../../../utils/logger.mts'
9-
10-
import type { NotificationReport } from './report.mts'
1110

1211
type NotificationProvider = {
1312
name: string
1413
isEnabled: () => boolean
1514
send: (report: NotificationReport) => Promise<void>
1615
}
1716

18-
const notificationProviders: NotificationProvider[] = [
19-
{
20-
name: 'Jira',
21-
isEnabled: isJiraEnabled,
22-
send: sendJiraTaskNotification,
23-
},
24-
{
25-
name: 'Slack',
26-
isEnabled: isSlackNotificationConfigured,
27-
send: async report => {
28-
const config = getSlackNotificationConfig() ?? null
29-
await sendSlackWebhookNotifications(report, config)
30-
await sendSlackBotNotifications(report, config)
31-
},
32-
},
33-
]
34-
3517
/** Deliver reports to each independently configured notification provider. */
3618
export async function dispatchScanNotifications(
3719
report: NotificationReport,
3820
): Promise<void> {
21+
const config = getSlackNotificationConfig() ?? null
22+
const notificationProviders: NotificationProvider[] = [
23+
{
24+
name: 'Jira',
25+
isEnabled: isJiraEnabled,
26+
send: sendJiraTaskNotification,
27+
},
28+
{
29+
name: 'Slack webhook',
30+
isEnabled: isSlackWebhookConfigured,
31+
send: report => sendSlackWebhookNotifications(report, config),
32+
},
33+
{
34+
name: 'Slack bot',
35+
// biome-ignore lint/complexity/useLiteralKeys: process.env uses an index signature.
36+
isEnabled: () => Boolean(process.env['SOCKET_SLACK_BOT_TOKEN']),
37+
send: report => sendSlackBotNotifications(report, config),
38+
},
39+
]
40+
3941
for (const provider of notificationProviders) {
4042
if (!provider.isEnabled()) {
4143
continue
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { afterEach, describe, expect, it, vi } from 'vitest'
2+
3+
import type { NotificationReport } from './report.mts'
4+
5+
const {
6+
sendJiraTaskNotification,
7+
sendSlackWebhookNotifications,
8+
sendSlackBotNotifications,
9+
} = vi.hoisted(() => ({
10+
sendJiraTaskNotification: vi.fn(),
11+
sendSlackWebhookNotifications: vi.fn(),
12+
sendSlackBotNotifications: vi.fn(),
13+
}))
14+
15+
vi.mock('./jira.mts', () => ({
16+
isJiraEnabled: () => true,
17+
sendJiraTaskNotification,
18+
}))
19+
vi.mock('./slack-webhook.mts', () => ({
20+
getSlackNotificationConfig: () => ({}),
21+
isSlackWebhookConfigured: () => true,
22+
sendSlackWebhookNotifications,
23+
}))
24+
vi.mock('./slack-bot.mts', () => ({ sendSlackBotNotifications }))
25+
vi.mock('../../../utils/logger.mts', () => ({
26+
logger: { warn: vi.fn() },
27+
}))
28+
29+
import { dispatchScanNotifications } from './dispatch.mts'
30+
31+
const report: NotificationReport = {
32+
kind: 'diff',
33+
diffScanId: 'diff-42',
34+
scanId: 'scan-42',
35+
repository: 'example/service',
36+
branch: 'feature/fix',
37+
pullRequest: 42,
38+
commitSha: '1234567890abcdef',
39+
scanUrl: 'https://socket.dev/dashboard/org/example/diff/base/scan-42',
40+
decision: 'fail',
41+
summary: '1 finding (1 blocking, 0 warning)',
42+
reachabilityEnabled: true,
43+
reachabilitySummary: '1 reachable',
44+
findings: [],
45+
reachabilityFindings: [
46+
{
47+
packageName: 'left-pad',
48+
ecosystem: 'npm',
49+
version: '1.0.0',
50+
alertType: 'cve',
51+
severity: 'high',
52+
action: 'error',
53+
advisoryId: 'GHSA-1234',
54+
purl: 'pkg:npm/left-pad@1.0.0',
55+
url: 'https://socket.dev/npm/package/left-pad/overview/1.0.0',
56+
reachability: 'reachable',
57+
},
58+
],
59+
}
60+
61+
afterEach(() => {
62+
vi.unstubAllEnvs()
63+
vi.clearAllMocks()
64+
})
65+
66+
describe('scan notification dispatch', () => {
67+
it('sends the same report to Jira and both Slack transports despite a provider failure', async () => {
68+
vi.stubEnv('SOCKET_SLACK_BOT_TOKEN', 'xoxb-test-token')
69+
sendJiraTaskNotification.mockRejectedValueOnce(
70+
new Error('Jira unavailable'),
71+
)
72+
sendSlackWebhookNotifications.mockRejectedValueOnce(
73+
new Error('Slack webhook unavailable'),
74+
)
75+
76+
await expect(dispatchScanNotifications(report)).resolves.toBeUndefined()
77+
78+
expect(sendJiraTaskNotification).toHaveBeenCalledWith(report)
79+
expect(sendSlackWebhookNotifications).toHaveBeenCalledWith(report, {})
80+
expect(sendSlackBotNotifications).toHaveBeenCalledWith(report, {})
81+
})
82+
})

0 commit comments

Comments
 (0)