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
25 changes: 25 additions & 0 deletions docs/commands/scan/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,28 @@ socket scan create --report
The bot posts to Slack's `chat.postMessage` API. It checks both the HTTP status
and Slack's JSON `ok` response. Rate limits and API errors are reported without
printing the token or changing the scan decision.

## Jira CI tasks

The scan creation report flow can create one Jira Task per report with findings.
Reruns for the same repository, branch, pull request, and commit update the
existing task. If CI cannot provide a commit SHA, reruns use the stable
repository, branch, and pull request identity instead. Store the API token in
your CI secret store and enable Jira only for trusted jobs:

```sh
export SOCKET_JIRA_ENABLED=true
# Set SOCKET_JIRA_CONFIG_JSON from your CI secret store.
socket ci
```

Store a JSON value like this in `SOCKET_JIRA_CONFIG_JSON`:

```json
{"url":"https://example.atlassian.net","email":"bot@example.com","api_token":"<JIRA_API_TOKEN>","project":"SEC"}
```

`SOCKET_JIRA_CONFIG_JSON` requires an HTTPS Jira base URL, the Atlassian account
email, an API token, and a Jira project key. Notifications include the Socket
report link, package, alert, source, and manifest details. Jira lookup or
delivery failures are reported as warnings and do not change the scan result.
21 changes: 20 additions & 1 deletion src/commands/ci/handle-ci.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { logger } from '../../utils/logger.mts'
import { getPackageFilesForScan } from '../../utils/path-resolve.mts'
import { serializeResultJson } from '../../utils/serialize-result-json.mts'
import { spawn } from '../../utils/spawn.mts'
import { fetchSupportedScanFileNames } from '../scan/fetch-supported-scan-file-names.mts'
import { handleCreateNewScan } from '../scan/handle-create-new-scan.mts'
import {
Expand Down Expand Up @@ -247,12 +248,30 @@ async function runCiScan({
)
debugDir('inspect', { orgSlug, cwd, branchName, repoName })

// Branch builds also carry a revision, even without a PR context.
let commitHash =
pythonJsonContext.commitSha ||
process.env['GITHUB_SHA'] ||
process.env['CI_COMMIT_SHA'] ||
process.env['BUILD_SOURCEVERSION'] ||
''
if (!commitHash) {
try {
const revision = await spawn('git', ['rev-parse', '--verify', 'HEAD'], {
cwd,
})
commitHash = revision.stdout.trim()
} catch {
debugFn('notice', 'No Git revision is available for this scan')
}
}

const [owner, repo] = constants.ENV.GITHUB_REPOSITORY.split('/')
await handleCreateNewScan({
autoManifest,
branchName,
commitMessage: '',
commitHash: '',
commitHash,
committers: '',
cwd,
defaultBranch: false,
Expand Down
4 changes: 4 additions & 0 deletions src/commands/scan/handle-create-new-scan.mts
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,8 @@ async function createNewScan(
notificationContext: {
repository: repoName,
branch: branchName,
pullRequest,
commitSha: commitHash || undefined,
reachabilityEnabled,
reachabilityFacts: notificationReachabilityFacts,
},
Expand All @@ -646,6 +648,8 @@ async function createNewScan(
notificationContext: {
repository: repoName,
branch: branchName,
pullRequest,
commitSha: commitHash || undefined,
reachabilityEnabled,
reachabilityFacts: notificationReachabilityFacts,
},
Expand Down
52 changes: 52 additions & 0 deletions src/commands/scan/notifications/dispatch.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { isJiraEnabled, sendJiraTaskNotification } from './jira.mts'
import { sendSlackBotNotifications } from './slack-bot.mts'
import {
getSlackNotificationConfig,
isSlackNotificationConfigured,
sendSlackWebhookNotifications,
} from './slack-webhook.mts'
import { logger } from '../../../utils/logger.mts'

import type { NotificationReport } from './report.mts'

type NotificationProvider = {
name: string
isEnabled: () => boolean
send: (report: NotificationReport) => Promise<void>
}

const notificationProviders: NotificationProvider[] = [
{
name: 'Jira',
isEnabled: isJiraEnabled,
send: sendJiraTaskNotification,
},
{
name: 'Slack',
isEnabled: isSlackNotificationConfigured,
send: async report => {
const config = getSlackNotificationConfig() ?? null
await sendSlackWebhookNotifications(report, config)
await sendSlackBotNotifications(report, config)
},
},
]

/** Deliver reports to each independently configured notification provider. */
export async function dispatchScanNotifications(
report: NotificationReport,
): Promise<void> {
for (const provider of notificationProviders) {
if (!provider.isEnabled()) {
continue
}
try {
// eslint-disable-next-line no-await-in-loop -- Providers are dispatched independently in order.
await provider.send(report)
} catch {
logger.warn(
`${provider.name} notification delivery failed; scan policy is unchanged.`,
)
}
}
}
Loading
Loading