Skip to main content
REST API 现已经过版本控制。 有关详细信息,请参阅“关于 API 版本控制”。

适用于依赖项提交的 REST API 终结点

使用 REST API 提交依赖项。

关于依赖项提交

可以使用 REST API 提交项目的依赖项。 这使你可以将依赖项(如编译或生成软件时解析的依赖项)添加到 GitHub 的依赖项关系图功能,从而更全面地了解项目的所有依赖项。

依赖项关系图显示你使用 API 提交的任何依赖项,以及从存储库中的清单或锁定文件(例如 package-lock.json JavaScript 项目中的文件)标识的任何依赖项。 有关查看依赖项关系图的详细信息,请参阅“探索仓库的依赖项”。

提交的依赖项将收到 Dependabot alerts 和 Dependabot security updates 以处理任何已知的漏洞。 你只会收到来自 GitHub Advisory Database 支持的生态系统之一的依赖关系的 Dependabot alerts。 有关这些生态系统的详细信息,请参阅“关于 GitHub 公告数据库”。 对于通过 依赖项提交 API 提交的可传递依赖项,如果更新可用,Dependabot 将自动打开拉取请求以更新父依赖项。

提交的依赖项将会显示在依赖项审查中,但_不会_显示在组织的依赖项见解中。

注意: 依赖关系审查 API 和 依赖项提交 API 协同工作。 这意味着依赖关系审查 API 将包括通过 依赖项提交 API 提交的依赖关系。

__

可以通过快照的形式提交依赖项。 快照是一组与提交 SHA 和其他元数据关联的依赖项,反映提交存储库的当前状态。 可以选择使用预先创建的操作,或创建自己的操作,在每次生成项目时,以所需的格式提交依赖项。 有关详细信息,请参阅“使用依赖项提交 API”。

可以提交多个依赖项集,以包含在依赖项关系图中。 REST API 使用快照的 job.correlator 属性和 detector.name 类别来确保显示每个工作流的最新提交。 属性 correlator 本身是用于保持独立提交不同的主要字段。 例如 correlator 可以是操作运行中两个可用变量的简单组合:<GITHUB_WORKFLOW> <GITHUB_JOB>

Create a snapshot of dependencies for a repository

Create a new snapshot of a repository's dependencies.

The authenticated user must have access to the repository.

OAuth app tokens and personal access tokens (classic) need the repo scope to use this endpoint.

“Create a snapshot of dependencies for a repository”的细粒度访问令牌

此端点支持以下精细令牌类型:

精细令牌必须具有以下权限集:

  • "Contents" repository permissions (write)

“Create a snapshot of dependencies for a repository”的参数

标头
名称, 类型, 说明
accept string

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

路径参数
名称, 类型, 说明
owner string 必须

The account owner of the repository. The name is not case sensitive.

repo string 必须

The name of the repository without the .git extension. The name is not case sensitive.

正文参数
名称, 类型, 说明
version integer 必须

The version of the repository snapshot submission.

job object 必须
名称, 类型, 说明
id string 必须

The external ID of the job.

correlator string 必须

Correlator provides a key that is used to group snapshots submitted over time. Only the "latest" submitted snapshot for a given combination of job.correlator and detector.name will be considered when calculating a repository's current dependencies. Correlator should be as unique as it takes to distinguish all detection runs for a given "wave" of CI workflow you run. If you're using GitHub Actions, a good default value for this could be the environment variables GITHUB_WORKFLOW and GITHUB_JOB concatenated together. If you're using a build matrix, then you'll also need to add additional key(s) to distinguish between each submission inside a matrix variation.

html_url string

The url for the job.

sha string 必须

The commit SHA associated with this dependency snapshot. Maximum length: 40 characters.

ref string 必须

The repository branch that triggered this snapshot.

detector object 必须

A description of the detector used.

名称, 类型, 说明
name string 必须

The name of the detector used.

version string 必须

The version of the detector used.

url string 必须

The url of the detector used.

metadata object

User-defined metadata to store domain-specific information limited to 8 keys with scalar values.

manifests object

A collection of package manifests, which are a collection of related dependencies declared in a file or representing a logical group of dependencies.

名称, 类型, 说明
key object

A user-defined key to represent an item in manifests.

名称, 类型, 说明
name string 必须

The name of the manifest.

file object
名称, 类型, 说明
source_location string

The path of the manifest file relative to the root of the Git repository.

metadata object

User-defined metadata to store domain-specific information limited to 8 keys with scalar values.

resolved object

A collection of resolved package dependencies.

名称, 类型, 说明
key object

A user-defined key to represent an item in resolved.

名称, 类型, 说明
package_url string

Package-url (PURL) of dependency. See https://github.com/package-url/purl-spec for more details.

metadata object

User-defined metadata to store domain-specific information limited to 8 keys with scalar values.

relationship string

A notation of whether a dependency is requested directly by this manifest or is a dependency of another dependency.

可以是以下选项之一: direct, indirect

scope string

A notation of whether the dependency is required for the primary build artifact (runtime) or is only used for development. Future versions of this specification may allow for more granular scopes.

可以是以下选项之一: runtime, development

dependencies array of strings

Array of package-url (PURLs) of direct child dependencies.

scanned string 必须

The time at which the snapshot was scanned.

“Create a snapshot of dependencies for a repository”的 HTTP 响应状态代码

状态代码说明
201

Created

“Create a snapshot of dependencies for a repository”的示例代码

如果你通过 GHE.com 访问 GitHub,请将 api.github.com 替换为你的企业在 api.SUBDOMAIN.ghe.com 上的专用子域。

请求示例

post/repos/{owner}/{repo}/dependency-graph/snapshots
curl -L \ -X POST \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>" \ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/repos/OWNER/REPO/dependency-graph/snapshots \ -d '{"version":0,"sha":"ce587453ced02b1526dfb4cb910479d431683101","ref":"refs/heads/main","job":{"correlator":"yourworkflowname_youractionname","id":"yourrunid"},"detector":{"name":"octo-detector","version":"0.0.1","url":"https://github.com/octo-org/octo-repo"},"scanned":"2022-06-14T20:25:00Z","manifests":{"package-lock.json":{"name":"package-lock.json","file":{"source_location":"src/package-lock.json"},"resolved":{"@actions/core":{"package_url":"pkg:/npm/%40actions/core@1.1.9","dependencies":["@actions/http-client"]},"@actions/http-client":{"package_url":"pkg:/npm/%40actions/http-client@1.0.7","dependencies":["tunnel"]},"tunnel":{"package_url":"pkg:/npm/tunnel@0.0.6"}}}}}'

Response

Status: 201
{ "id": 12345, "created_at": "2018-05-04T01:14:52Z", "message": "Dependency results for the repo have been successfully updated.", "result": "SUCCESS" }