Skip to content

Commit 6b14ee3

Browse files
committed
feat(python-cli-parity): create Jira tasks from scan reports
1 parent 459af52 commit 6b14ee3

9 files changed

Lines changed: 748 additions & 58 deletions

File tree

‎docs/commands/scan/report.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,27 @@ socket scan create --report
8787
The bot posts to Slack's `chat.postMessage` API. It checks both the HTTP status
8888
and Slack's JSON `ok` response. Rate limits and API errors are reported without
8989
printing the token or changing the scan decision.
90+
91+
## Jira CI tasks
92+
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:
97+
98+
```sh
99+
export SOCKET_JIRA_ENABLED=true
100+
# Set SOCKET_JIRA_CONFIG_JSON from your CI secret store.
101+
socket ci
102+
```
103+
104+
Store a JSON value like this in `SOCKET_JIRA_CONFIG_JSON`:
105+
106+
```json
107+
{"url":"https://example.atlassian.net","email":"bot@example.com","api_token":"<JIRA_API_TOKEN>","project":"SEC"}
108+
```
109+
110+
`SOCKET_JIRA_CONFIG_JSON` requires an HTTPS Jira base URL, the Atlassian account
111+
email, an API token, and a Jira project key. Notifications include the Socket
112+
report link, package, alert, source, and manifest details. Jira lookup or
113+
delivery failures are reported as warnings and do not change the scan result.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ async function createNewScan(
629629
notificationContext: {
630630
repository: repoName,
631631
branch: branchName,
632+
pullRequest,
633+
commitSha: commitHash || undefined,
632634
reachabilityEnabled,
633635
reachabilityFacts: notificationReachabilityFacts,
634636
},
@@ -646,6 +648,8 @@ async function createNewScan(
646648
notificationContext: {
647649
repository: repoName,
648650
branch: branchName,
651+
pullRequest,
652+
commitSha: commitHash || undefined,
649653
reachabilityEnabled,
650654
reachabilityFacts: notificationReachabilityFacts,
651655
},
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { isJiraEnabled, sendJiraTaskNotification } from './jira.mts'
2+
import { sendSlackBotNotifications } from './slack-bot.mts'
3+
import {
4+
getSlackNotificationConfig,
5+
isSlackNotificationConfigured,
6+
sendSlackWebhookNotifications,
7+
} from './slack-webhook.mts'
8+
import { logger } from '../../../utils/logger.mts'
9+
10+
import type { NotificationReport } from './report.mts'
11+
12+
type NotificationProvider = {
13+
name: string
14+
isEnabled: () => boolean
15+
send: (report: NotificationReport) => Promise<void>
16+
}
17+
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+
35+
/** Deliver reports to each independently configured notification provider. */
36+
export async function dispatchScanNotifications(
37+
report: NotificationReport,
38+
): Promise<void> {
39+
for (const provider of notificationProviders) {
40+
if (!provider.isEnabled()) {
41+
continue
42+
}
43+
try {
44+
// eslint-disable-next-line no-await-in-loop -- Providers are dispatched independently in order.
45+
await provider.send(report)
46+
} catch {
47+
logger.warn(
48+
`${provider.name} notification delivery failed; scan policy is unchanged.`,
49+
)
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)