Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

代码扫描

code scanning API 可让您从仓库检索和更新 code scanning 警报。

关于代码扫描 API

code scanning API 可让您从仓库检索和更新 code scanning 警报。 您可以使用端点为组织中的 code scanning 警报创建自动报告,或上传使用离线 code scanning 工具生成的分析结果。 有关详细信息,请参阅“查找代码中的安全漏洞和错误”。

code scanning 的自定义媒体类型

code scanning REST API 有一种支持的自定义媒体类型。

application/sarif+json

可以将此媒体类型用于发送到 /analyses/{analysis_id} 终结点的 GET 请求。 有关此操作的详细信息,请参阅“获取存储库的 code scanning 分析”。 将此媒体类型用于此操作时,响应包括为指定分析上传的实际数据的子集,而不是使用默认媒体类型时返回的分析摘要。 响应还包括其他数据,如 github/alertNumber 和 github/alertUrl 属性。 数据的格式为 SARIF 版本 2.1.0。

有关详细信息,请参阅“媒体类型”。

List code scanning alerts for an enterprise

Lists code scanning alerts for the default branch for all eligible repositories in an enterprise. Eligible repositories are repositories that are owned by organizations that you own or for which you are a security manager. For more information, see "Managing security managers in your organization."

To use this endpoint, you must be a member of the enterprise, and you must use an access token with the repo scope or security_events scope.

参数

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
enterprisestringRequired

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

Query parameters
Name, Type, Description
tool_namestring

The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either tool_name or tool_guid, but not both.

tool_guidstringnull

The GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either tool_guid or tool_name, but not both.

beforestring

A cursor, as given in the Link header. If specified, the query only searches for results before this cursor.

afterstring

A cursor, as given in the Link header. If specified, the query only searches for results after this cursor.

pageinteger

Page number of the results to fetch.

Default: 1

per_pageinteger

The number of results per page (max 100).

Default: 30

directionstring

The direction to sort the results by.

Default: desc

Can be one of: asc, desc

statestring

If specified, only code scanning alerts with this state will be returned.

Can be one of: open, closed, dismissed, fixed

sortstring

The property by which to sort the results.

Default: created

Can be one of: created, updated

HTTP 响应状态代码

状态代码说明
200

OK

404

Resource not found

503

Service unavailable

代码示例

get/enterprises/{enterprise}/code-scanning/alerts
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>"\ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/code-scanning/alerts

Response

Status: 200
[ { "number": 4, "