Get a code scanning alert

Gets a single code scanning alert. You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events read permission to use this endpoint.

The security alert_number is found at the end of the security alert's URL. For example, the security alert ID for https://github.com/Octo-org/octo-repo/security/code-scanning/88 is 88.

octokit.codeScanning.getAlert({
owner,
repo,
alert_number,
});

Parameters

namerequireddescription
owneryes
repoyes
alert_numberyes
alert_idno

See also: GitHub Developer Guide documentation.

List code scanning alerts for a repository

Lists all open code scanning alerts for the default branch (usually main or master). You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events read permission to use this endpoint.

octokit.codeScanning.listAlertsForRepo({
owner,
repo,
});

Parameters

namerequireddescription
owneryes
repoyes
stateno

Set to open, fixed, or dismissed to list code scanning alerts in a specific state.

refno

Set a full Git reference to list alerts for a specific branch. The ref must be formatted as refs/heads/<branch name>.

See also: GitHub Developer Guide documentation.

List recent code scanning analyses for a repository

List the details of recent code scanning analyses for a repository. You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events read permission to use this endpoint.

octokit.codeScanning.listRecentAnalyses({
owner,
repo,
});

Parameters

namerequireddescription
owneryes
repoyes
refno

Set a full Git reference to list alerts for a specific branch. The ref must be formatted as refs/heads/<branch name>.

tool_nameno

Set a single code scanning tool name to filter alerts by tool.

See also: GitHub Developer Guide documentation.

Update a code scanning alert

Updates the status of a single code scanning alert. You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events write permission to use this endpoint.

octokit.codeScanning.updateAlert({
owner,
repo,
alert_number,
state,
});

Parameters

namerequireddescription
owneryes
repoyes
alert_numberyes

The security alert number, found at the end of the security alert's URL.

stateyes

Sets the state of the code scanning alert. Can be one of open or dismissed. You must provide dismissed_reason when you set the state to dismissed.

dismissed_reasonno

Required when the state is dismissed. The reason for dismissing or closing the alert. Can be one of: false positive, won't fix, and used in tests.

See also: GitHub Developer Guide documentation.

Upload a SARIF file

Upload a SARIF file containing the results of a code scanning analysis to make the results available in a repository. You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events write permission to use this endpoint.

octokit.codeScanning.uploadSarif({
owner,
repo,
commit_sha,
ref,
sarif,
tool_name,
});

Parameters

namerequireddescription
owneryes
repoyes
commit_shayes

The commit SHA of the code scanning analysis file.

refyes

The full Git reference of the code scanning analysis file, formatted as refs/heads/<branch name>.

sarifyes

A Base64 string representing the SARIF file to upload. You must first compress your SARIF file using gzip and then translate the contents of the file into a Base64 encoding string.

checkout_urino

The base directory used in the analysis, as it appears in the SARIF file. This property is used to convert file paths from absolute to relative, so that alerts can be mapped to their correct location in the repository.

started_atno

The time that the analysis run began. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ.

tool_nameyes

The name of the tool used to generate the code scanning analysis alert.

See also: GitHub Developer Guide documentation.